Docker template generator
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dotege_test.go 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package main
  2. import (
  3. "reflect"
  4. "testing"
  5. )
  6. func Test_wildcardMatches(t *testing.T) {
  7. type args struct {
  8. wildcard string
  9. domain string
  10. }
  11. tests := []struct {
  12. name string
  13. args args
  14. want bool
  15. }{
  16. {"non-matching", args{"example.com", "example.org"}, false},
  17. {"same level domain", args{"example.com", "example.com"}, false},
  18. {"single level sub domain", args{"example.com", "foo.example.com"}, true},
  19. {"multi level sub domain", args{"example.com", "bar.foo.example.com"}, false},
  20. }
  21. for _, tt := range tests {
  22. t.Run(tt.name, func(t *testing.T) {
  23. if got := wildcardMatches(tt.args.wildcard, tt.args.domain); got != tt.want {
  24. t.Errorf("wildcardMatches() = %v, want %v", got, tt.want)
  25. }
  26. })
  27. }
  28. }
  29. func Test_applyWildcards(t *testing.T) {
  30. type args struct {
  31. domains []string
  32. wildcards []string
  33. }
  34. tests := []struct {
  35. name string
  36. args args
  37. want []string
  38. }{
  39. {"no wildcards", args{[]string{"example.com", "example.org"}, []string{}}, []string{"example.com", "example.org"}},
  40. {"non-matching wildcards", args{[]string{"example.com", "example.org"}, []string{"example.net"}}, []string{"example.com", "example.org"}},
  41. {"single match", args{[]string{"foo.example.com", "example.org"}, []string{"example.com"}}, []string{"*.example.com", "example.org"}},
  42. {"multiple matches", args{[]string{"foo.example.com", "example.org", "bar.example.com"}, []string{"example.com"}}, []string{"*.example.com", "example.org"}},
  43. {"multiple wildcards", args{[]string{"foo.example.com", "baz.example.org", "bar.example.com"}, []string{"example.com", "example.org"}}, []string{"*.example.com", "*.example.org"}},
  44. }
  45. for _, tt := range tests {
  46. t.Run(tt.name, func(t *testing.T) {
  47. if got := applyWildcards(tt.args.domains, tt.args.wildcards); !reflect.DeepEqual(got, tt.want) {
  48. t.Errorf("applyWildcards() = %v, want %v", got, tt.want)
  49. }
  50. })
  51. }
  52. }