matcher_test.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package namematcher
  2. import "testing"
  3. import . "github.com/smartystreets/goconvey/convey"
  4. func TestMatchMember(t *testing.T) {
  5. testingVector := []struct {
  6. matcher string
  7. target string
  8. expects bool
  9. }{
  10. {matcher: "", target: "", expects: true},
  11. {matcher: "^snowflake.torproject.net$", target: "snowflake.torproject.net", expects: true},
  12. {matcher: "^snowflake.torproject.net$", target: "faketorproject.net", expects: false},
  13. {matcher: "snowflake.torproject.net$", target: "faketorproject.net", expects: false},
  14. {matcher: "snowflake.torproject.net$", target: "snowflake.torproject.net", expects: true},
  15. {matcher: "snowflake.torproject.net$", target: "imaginary-01-snowflake.torproject.net", expects: true},
  16. {matcher: "snowflake.torproject.net$", target: "imaginary-aaa-snowflake.torproject.net", expects: true},
  17. {matcher: "snowflake.torproject.net$", target: "imaginary-aaa-snowflake.faketorproject.net", expects: false},
  18. }
  19. for _, v := range testingVector {
  20. t.Run(v.matcher+"<>"+v.target, func(t *testing.T) {
  21. Convey("test", t, func() {
  22. matcher := NewNameMatcher(v.matcher)
  23. So(matcher.IsMember(v.target), ShouldEqual, v.expects)
  24. })
  25. })
  26. }
  27. }
  28. func TestMatchSubset(t *testing.T) {
  29. testingVector := []struct {
  30. matcher string
  31. target string
  32. expects bool
  33. }{
  34. {matcher: "", target: "", expects: true},
  35. {matcher: "^snowflake.torproject.net$", target: "^snowflake.torproject.net$", expects: true},
  36. {matcher: "snowflake.torproject.net$", target: "^snowflake.torproject.net$", expects: true},
  37. {matcher: "snowflake.torproject.net$", target: "snowflake.torproject.net$", expects: true},
  38. {matcher: "snowflake.torproject.net$", target: "testing-snowflake.torproject.net$", expects: true},
  39. {matcher: "snowflake.torproject.net$", target: "^testing-snowflake.torproject.net$", expects: true},
  40. {matcher: "snowflake.torproject.net$", target: "", expects: false},
  41. }
  42. for _, v := range testingVector {
  43. t.Run(v.matcher+"<>"+v.target, func(t *testing.T) {
  44. Convey("test", t, func() {
  45. matcher := NewNameMatcher(v.matcher)
  46. target := NewNameMatcher(v.target)
  47. So(matcher.IsSupersetOf(target), ShouldEqual, v.expects)
  48. })
  49. })
  50. }
  51. }