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.
 
 
 

42 lines
1.3 KiB

  1. // copyright 2016 google inc. all rights reserved.
  2. //
  3. // licensed under the apache license, version 2.0 (the "license");
  4. // you may not use this file except in compliance with the license.
  5. // you may obtain a copy of the license at
  6. //
  7. // http://www.apache.org/licenses/license-2.0
  8. //
  9. // unless required by applicable law or agreed to in writing, software
  10. // distributed under the license is distributed on an "as is" basis,
  11. // without warranties or conditions of any kind, either express or implied.
  12. // see the license for the specific language governing permissions and
  13. // limitations under the license.
  14. package martianurl
  15. import "testing"
  16. func TestMatchHost(t *testing.T) {
  17. tt := []struct {
  18. host, match string
  19. want bool
  20. }{
  21. {"example.com", "example.com", true},
  22. {"example.com", "example.org", false},
  23. {"ample.com", "example.com", false},
  24. {"example.com", "ample.com", false},
  25. {"example.com", "example.*", true},
  26. {"www.example.com", "*.example.com", true},
  27. {"one.two.example.com", "*.example.com", false},
  28. {"one.two.example.com", "*.*.example.com", true},
  29. {"", "", false},
  30. {"", "foo", false},
  31. }
  32. for i, tc := range tt {
  33. if got := MatchHost(tc.host, tc.match); got != tc.want {
  34. t.Errorf("%d. MatchHost(%s, %s): got %t, want %t", i, tc.host, tc.match, got, tc.want)
  35. }
  36. }
  37. }