github.com/Cloud-Foundations/Dominator@v0.3.4/lib/url/urlutil/parseUrl_test.go (about) 1 package urlutil 2 3 import ( 4 "testing" 5 ) 6 7 func TestFilePlain(t *testing.T) { 8 pathname := "/dir0/dir1/file2" 9 driverData, err := parseUrl(pathname) 10 if err != nil { 11 t.Fatal(err) 12 } 13 if driverFile != driverData.driverType { 14 t.Fatalf("expected driverType:%d, got: %d", 15 driverFile, driverData.driverType) 16 } 17 if pathname != driverData.pathname { 18 t.Fatalf("expected pathname: \"%s\", got: \"%s\"", 19 pathname, driverData.pathname) 20 } 21 } 22 23 func TestFileUrl(t *testing.T) { 24 pathname := "/dir0/dir1/file2" 25 driverData, err := parseUrl("file://" + pathname) 26 if err != nil { 27 t.Fatal(err) 28 } 29 if driverFile != driverData.driverType { 30 t.Fatalf("expected driverType:%d, got: %d", 31 driverFile, driverData.driverType) 32 } 33 if pathname != driverData.pathname { 34 t.Fatalf("expected pathname: \"%s\", got: \"%s\"", 35 pathname, driverData.pathname) 36 } 37 } 38 39 func TestGitHTTP(t *testing.T) { 40 pathname := "dir0/dir1/file2" 41 repo := "http://github.com/Cloud-Foundations/bogus.git" 42 driverData, err := parseUrl(repo + "?" + pathname) 43 if err != nil { 44 t.Fatal(err) 45 } 46 if driverGit != driverData.driverType { 47 t.Fatalf("expected driverType:%d, got: %d", 48 driverGit, driverData.driverType) 49 } 50 if repo != driverData.gitUrl { 51 t.Fatalf("expected repo: \"%s\", got: \"%s\"", 52 repo, driverData.gitUrl) 53 } 54 if pathname != driverData.pathname { 55 t.Fatalf("expected pathname: \"%s\", got: \"%s\"", 56 pathname, driverData.pathname) 57 } 58 } 59 60 func TestGitHttpIncomplete(t *testing.T) { 61 repo := "http://github.com/Cloud-Foundations/bogus.git?" 62 _, err := parseUrl(repo) 63 if err == nil { 64 t.Fatal("expected parse error") 65 } 66 } 67 68 func TestGitHttpMissing(t *testing.T) { 69 repo := "http://github.com/Cloud-Foundations/bogus.git" 70 _, err := parseUrl(repo) 71 if err == nil { 72 t.Fatal("expected parse error") 73 } 74 } 75 76 func TestGitSSH(t *testing.T) { 77 pathname := "dir0/dir1/file2" 78 repo := "git@github.com:Cloud-Foundations/bogus.git" 79 driverData, err := parseUrl(repo + "/" + pathname) 80 if err != nil { 81 t.Fatal(err) 82 } 83 if driverGit != driverData.driverType { 84 t.Fatalf("expected driverType:%d, got: %d", 85 driverGit, driverData.driverType) 86 } 87 if repo != driverData.gitUrl { 88 t.Fatalf("expected repo: \"%s\", got: \"%s\"", 89 repo, driverData.gitUrl) 90 } 91 if pathname != driverData.pathname { 92 t.Fatalf("expected pathname: \"%s\", got: \"%s\"", 93 pathname, driverData.pathname) 94 } 95 } 96 97 func TestGitSshIncomplete(t *testing.T) { 98 repo := "git@github.com:Cloud-Foundations/bogus.git/" 99 _, err := parseUrl(repo) 100 if err == nil { 101 t.Fatal("expected parse error") 102 } 103 } 104 105 func TestGitSshMissing(t *testing.T) { 106 repo := "git@github.com:Cloud-Foundations/bogus.git" 107 _, err := parseUrl(repo) 108 if err == nil { 109 t.Fatal("expected parse error") 110 } 111 } 112 113 func TestHTTP(t *testing.T) { 114 url := "http://www.website.com/dir0/dir1/file2" 115 driverData, err := parseUrl(url) 116 if err != nil { 117 t.Fatal(err) 118 } 119 if driverHttp != driverData.driverType { 120 t.Fatalf("expected driverType:%d, got: %d", 121 driverHttp, driverData.driverType) 122 } 123 if url != driverData.rawUrl { 124 t.Fatalf("expected URL: \"%s\", got: \"%s\"", 125 url, driverData.rawUrl) 126 } 127 }