github.com/hooklift/terraform@v0.11.0-beta1.0.20171117000744-6786c1361ffe/svchost/disco/host_test.go (about) 1 package disco 2 3 import ( 4 "net/url" 5 "testing" 6 ) 7 8 func TestHostServiceURL(t *testing.T) { 9 baseURL, _ := url.Parse("https://example.com/disco/foo.json") 10 host := Host{ 11 discoURL: baseURL, 12 services: map[string]interface{}{ 13 "absolute.v1": "http://example.net/foo/bar", 14 "absolutewithport.v1": "http://example.net:8080/foo/bar", 15 "relative.v1": "./stu/", 16 "rootrelative.v1": "/baz", 17 "protorelative.v1": "//example.net/", 18 "withfragment.v1": "http://example.org/#foo", 19 "querystring.v1": "https://example.net/baz?foo=bar", 20 "nothttp.v1": "ftp://127.0.0.1/pub/", 21 "invalid.v1": "***not A URL at all!:/<@@@@>***", 22 }, 23 } 24 25 tests := []struct { 26 ID string 27 Want string 28 }{ 29 {"absolute.v1", "http://example.net/foo/bar"}, 30 {"absolutewithport.v1", "http://example.net:8080/foo/bar"}, 31 {"relative.v1", "https://example.com/disco/stu/"}, 32 {"rootrelative.v1", "https://example.com/baz"}, 33 {"protorelative.v1", "https://example.net/"}, 34 {"withfragment.v1", "http://example.org/"}, 35 {"querystring.v1", "https://example.net/baz?foo=bar"}, // most callers will disregard query string 36 {"nothttp.v1", "<nil>"}, 37 {"invalid.v1", "<nil>"}, 38 } 39 40 for _, test := range tests { 41 t.Run(test.ID, func(t *testing.T) { 42 url := host.ServiceURL(test.ID) 43 var got string 44 if url != nil { 45 got = url.String() 46 } else { 47 got = "<nil>" 48 } 49 50 if got != test.Want { 51 t.Errorf("wrong result\ngot: %s\nwant: %s", got, test.Want) 52 } 53 }) 54 } 55 }