github.com/ndarilek/terraform@v0.3.8-0.20150320140257-d3135c1b2bac/helper/url/url_test.go (about) 1 package url 2 3 import ( 4 "runtime" 5 "testing" 6 ) 7 8 type parseTest struct { 9 rawURL string 10 scheme string 11 host string 12 path string 13 str string 14 err bool 15 } 16 17 var parseTests = []parseTest{ 18 { 19 rawURL: "/foo/bar", 20 scheme: "", 21 host: "", 22 path: "/foo/bar", 23 str: "/foo/bar", 24 err: false, 25 }, 26 { 27 rawURL: "file:///dir/", 28 scheme: "file", 29 host: "", 30 path: "/dir/", 31 str: "file:///dir/", 32 err: false, 33 }, 34 } 35 36 var winParseTests = []parseTest{ 37 { 38 rawURL: `C:\`, 39 scheme: ``, 40 host: ``, 41 path: `C:/`, 42 str: `C:/`, 43 err: false, 44 }, 45 { 46 rawURL: `file://C:\`, 47 scheme: `file`, 48 host: ``, 49 path: `C:/`, 50 str: `file://C:/`, 51 err: false, 52 }, 53 { 54 rawURL: `file:///C:\`, 55 scheme: `file`, 56 host: ``, 57 path: `C:/`, 58 str: `file://C:/`, 59 err: false, 60 }, 61 } 62 63 func TestParse(t *testing.T) { 64 if runtime.GOOS == "windows" { 65 parseTests = append(parseTests, winParseTests...) 66 } 67 for i, pt := range parseTests { 68 url, err := Parse(pt.rawURL) 69 if err != nil && !pt.err { 70 t.Errorf("test %d: unexpected error: %s", i, err) 71 } 72 if err == nil && pt.err { 73 t.Errorf("test %d: expected an error", i) 74 } 75 if url.Scheme != pt.scheme { 76 t.Errorf("test %d: expected Scheme = %q, got %q", i, pt.scheme, url.Scheme) 77 } 78 if url.Host != pt.host { 79 t.Errorf("test %d: expected Host = %q, got %q", i, pt.host, url.Host) 80 } 81 if url.Path != pt.path { 82 t.Errorf("test %d: expected Path = %q, got %q", i, pt.path, url.Path) 83 } 84 if url.String() != pt.str { 85 t.Errorf("test %d: expected url.String() = %q, got %q", i, pt.str, url.String()) 86 } 87 } 88 }