@@ -213,19 +213,14 @@ func getDigestAsString(image v1.Image) string {
213
213
return digestHash .String ()
214
214
}
215
215
216
- func TestGetRemoteEntrypoint (t * testing.T ) {
217
- expectedEntrypoint := []string {"/bin/expected" , "entrypoint" }
218
- img := getImage (t , & v1.ConfigFile {
219
- Config : v1.Config {
220
- Entrypoint : expectedEntrypoint ,
221
- },
222
- })
216
+ func getServer (t * testing.T , img v1.Image ) * httptest.Server {
223
217
expectedRepo := "image"
224
- digetsSha := getDigestAsString ( img )
218
+
225
219
configPath := fmt .Sprintf ("/v2/%s/blobs/%s" , expectedRepo , mustConfigName (t , img ))
226
- manifestPath := fmt .Sprintf ("/v2/%s/manifests/%s" , expectedRepo , digetsSha )
220
+ manifestPath := fmt .Sprintf ("/v2/%s/manifests/%s" , expectedRepo , getDigestAsString (img ))
221
+ latestPath := fmt .Sprintf ("/v2/%s/manifests/latest" , expectedRepo )
227
222
228
- server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
223
+ return httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
229
224
switch r .URL .Path {
230
225
case "/v2/" :
231
226
w .WriteHeader (http .StatusOK )
@@ -236,7 +231,7 @@ func TestGetRemoteEntrypoint(t *testing.T) {
236
231
if _ , err := w .Write (mustRawConfigFile (t , img )); err != nil {
237
232
t .Fatal (err )
238
233
}
239
- case manifestPath :
234
+ case manifestPath , latestPath :
240
235
if r .Method != http .MethodGet {
241
236
t .Errorf ("Method; got %v, want %v" , r .Method , http .MethodGet )
242
237
}
@@ -247,6 +242,19 @@ func TestGetRemoteEntrypoint(t *testing.T) {
247
242
t .Fatalf ("Unexpected path: %v" , r .URL .Path )
248
243
}
249
244
}))
245
+ }
246
+
247
+ func TestGetRemoteEntrypoint (t * testing.T ) {
248
+ expectedEntrypoint := []string {"/bin/expected" , "entrypoint" }
249
+ img := getImage (t , & v1.ConfigFile {
250
+ Config : v1.Config {
251
+ Entrypoint : expectedEntrypoint ,
252
+ },
253
+ })
254
+ expectedRepo := "image"
255
+ digetsSha := getDigestAsString (img )
256
+
257
+ server := getServer (t , img )
250
258
defer server .Close ()
251
259
image := path .Join (strings .TrimPrefix (server .URL , "http://" ), expectedRepo )
252
260
finalDigest := image + "@" + digetsSha
@@ -286,6 +294,68 @@ func TestGetRemoteEntrypoint(t *testing.T) {
286
294
}
287
295
}
288
296
297
+ func TestGetRemoteEntrypointStale (t * testing.T ) {
298
+ initialEntrypoint := []string {"/bin/expected" , "entrypoint" }
299
+ img := getImage (t , & v1.ConfigFile {
300
+ Config : v1.Config {
301
+ Entrypoint : initialEntrypoint ,
302
+ },
303
+ })
304
+
305
+ server := getServer (t , img )
306
+ defer server .Close ()
307
+ expectedRepo := "image"
308
+ image := path .Join (strings .TrimPrefix (server .URL , "http://" ), expectedRepo ) + ":latest"
309
+
310
+ entrypointCache , err := NewCache ()
311
+ if err != nil {
312
+ t .Fatalf ("couldn't create new entrypoint cache: %v" , err )
313
+ }
314
+ taskRun := & v1alpha1.TaskRun {
315
+ ObjectMeta : metav1.ObjectMeta {
316
+ Namespace : "foo" ,
317
+ Name : "taskRun" ,
318
+ },
319
+ Spec : v1alpha1.TaskRunSpec {
320
+ ServiceAccount : "default" ,
321
+ },
322
+ }
323
+ c := fakekubeclientset .NewSimpleClientset (& corev1.ServiceAccount {
324
+ ObjectMeta : metav1.ObjectMeta {
325
+ Name : "default" ,
326
+ Namespace : "foo" ,
327
+ },
328
+ })
329
+ ep1 , err := GetRemoteEntrypoint (entrypointCache , image , c , taskRun )
330
+ if err != nil {
331
+ t .Errorf ("couldn't get entrypoint remote: %v" , err )
332
+ }
333
+ server .Close ()
334
+
335
+ // Now change the image
336
+ secondEntrypoint := []string {"/bin/expected" , "entrypoint2" }
337
+ img = getImage (t , & v1.ConfigFile {
338
+ Config : v1.Config {
339
+ Entrypoint : secondEntrypoint ,
340
+ },
341
+ })
342
+ server2 := getServer (t , img )
343
+ image = path .Join (strings .TrimPrefix (server2 .URL , "http://" ), expectedRepo ) + ":latest"
344
+ defer server2 .Close ()
345
+ ep2 , err := GetRemoteEntrypoint (entrypointCache , image , c , taskRun )
346
+ if err != nil {
347
+ t .Fatalf ("couldn't get entrypoint remote: %v" , err )
348
+ }
349
+
350
+ if ! reflect .DeepEqual (ep1 , initialEntrypoint ) {
351
+ t .Errorf ("entrypoints do not match: %s should be %s" , ep1 , initialEntrypoint )
352
+ }
353
+
354
+ if ! reflect .DeepEqual (ep2 , secondEntrypoint ) {
355
+ t .Errorf ("entrypoints do not match: %s should be %s" , ep2 , secondEntrypoint )
356
+ }
357
+ }
358
+
289
359
func TestGetRemoteEntrypointWithNonDefaultSA (t * testing.T ) {
290
360
expectedEntrypoint := []string {"/bin/expected" , "entrypoint" }
291
361
img := getImage (t , & v1.ConfigFile {
0 commit comments