@@ -42,10 +42,13 @@ func TestGithubClient(t *testing.T) {
42
42
43
43
var _ = Describe ("GithubClient" , func () {
44
44
client , mux , serverURL , teardown = setupGitClient ()
45
- mux . HandleFunc ( "/repos/o/r/tarball" , func (w http.ResponseWriter , r * http.Request ) {
45
+ redirectArchive := func (w http.ResponseWriter , r * http.Request ) {
46
46
http .Redirect (w , r , serverURL + "/archive.tar.gz" , http .StatusFound )
47
47
return
48
- })
48
+ }
49
+ mux .HandleFunc ("/repos/o/r/tarball/" , redirectArchive )
50
+ mux .HandleFunc ("/repos/o/r/tarball" , redirectArchive )
51
+
49
52
mux .HandleFunc ("/archive.tar.gz" , func (w http.ResponseWriter , r * http.Request ) {
50
53
archiveData := `H4sIAJKjXFsAA+3WXW6CQBQFYJbCBmrv/D831ce+uIOpDtGEKQaoibt3qERbEmiNI6TxfC8TIwkXTg65lfW73D3ZcrXZ7t1zcg9EZJRKv059OonL09lKmRDcMM6k0SkxSYolqbrLNB2fVW3LMIoPr2DounBZlg383z7H+fwnqp/5v25sWc8O1ucR7xHeh5ZyKH9xzl+TDPkroylJKeIMvR48//fw8PC4Ov1fLl7mb4uZX8e8xzX9V4Y1/RdMof9jyIpi6hFgQp3+1y78tLWrYm6CV+1/oum/JqGx/42hN/+12+XFwbuPsA7euA3++v1n/LL/sZA/JyM4vv9juMQ89SQwhd7+V67cb1fu5vInf9n/zLf+y6b/nDP0fwxtzFOPAQAAAAAAAAAAAACRHQEZehxJACgAAA==`
51
54
dec := base64 .NewDecoder (base64 .StdEncoding , strings .NewReader (archiveData ))
@@ -127,6 +130,43 @@ var _ = Describe("GithubClient", func() {
127
130
Expect (err .Error ()).To (Equal ("http://gitlab.com/o/r is not a Github URL" ))
128
131
})
129
132
})
133
+
134
+ Context ("With a url path to a single file at the base of the repo" , func () {
135
+ It ("should fetch and persist the file" , func () {
136
+ validGithubURLSingle := "github.com/o/r/blob/master/Chart.yaml"
137
+ mockFs := afero.Afero {Fs : afero .NewMemMapFs ()}
138
+ gitClient := & GithubClient {
139
+ client : client ,
140
+ fs : mockFs ,
141
+ logger : log .NewNopLogger (),
142
+ }
143
+
144
+ err := gitClient .GetFiles (context .Background (), validGithubURLSingle , constants .HelmChartPath )
145
+
146
+ chart , err := gitClient .fs .ReadFile (path .Join (constants .HelmChartPath , "Chart.yaml" ))
147
+ Expect (err ).NotTo (HaveOccurred ())
148
+
149
+ Expect (string (chart )).To (Equal ("bar" ))
150
+ })
151
+ })
152
+
153
+ Context ("With a url path to a single nested file" , func () {
154
+ It ("should fetch and persist the file" , func () {
155
+ validGithubURLSingle := "github.com/o/r/blob/master/templates/service.yml"
156
+ mockFs := afero.Afero {Fs : afero .NewMemMapFs ()}
157
+ gitClient := & GithubClient {
158
+ client : client ,
159
+ fs : mockFs ,
160
+ logger : log .NewNopLogger (),
161
+ }
162
+
163
+ err := gitClient .GetFiles (context .Background (), validGithubURLSingle , constants .HelmChartPath )
164
+ chart , err := gitClient .fs .ReadFile (path .Join (constants .HelmChartPath , "templates" , "service.yml" ))
165
+ Expect (err ).NotTo (HaveOccurred ())
166
+
167
+ Expect (string (chart )).To (Equal ("service" ))
168
+ })
169
+ })
130
170
})
131
171
132
172
Describe ("decodeGitHubURL" , func () {
0 commit comments