github.com/google/martian/v3@v3.3.3/martianurl/host_test.go (about) 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 15 package martianurl 16 17 import "testing" 18 19 func TestMatchHost(t *testing.T) { 20 tt := []struct { 21 host, match string 22 want bool 23 }{ 24 {"example.com", "example.com", true}, 25 {"example.com", "example.org", false}, 26 {"ample.com", "example.com", false}, 27 {"example.com", "ample.com", false}, 28 {"example.com", "example.*", true}, 29 {"www.example.com", "*.example.com", true}, 30 {"one.two.example.com", "*.example.com", false}, 31 {"one.two.example.com", "*.*.example.com", true}, 32 {"", "", false}, 33 {"", "foo", false}, 34 } 35 36 for i, tc := range tt { 37 if got := MatchHost(tc.host, tc.match); got != tc.want { 38 t.Errorf("%d. MatchHost(%s, %s): got %t, want %t", i, tc.host, tc.match, got, tc.want) 39 } 40 } 41 }