@@ -264,7 +264,7 @@ func TestProjectChunk_hash(t *testing.T) {
264
264
BaseRef string
265
265
Chunk string
266
266
IncludeTests bool
267
- Expectation string
267
+ Expectation map [ string ] string
268
268
}{
269
269
{
270
270
Name : "base only no tests" ,
@@ -276,7 +276,7 @@ func TestProjectChunk_hash(t *testing.T) {
276
276
Base : "" ,
277
277
BaseRef : "" ,
278
278
Chunk : "base" ,
279
- Expectation : "550ccae3705ce9627190644ef89f404f94b8d6f9d13d8df537ca66080dd326b2" ,
279
+ Expectation : map [ string ] string { "base" : "02e46ef9c6d86deea6ffb67b6cd04a99e3600bb8d2c01f60359ed7a1ba2ed295" } ,
280
280
},
281
281
{
282
282
Name : "base with other tests should have same hash as no tests" ,
@@ -296,7 +296,7 @@ func TestProjectChunk_hash(t *testing.T) {
296
296
Base : "" ,
297
297
BaseRef : "" ,
298
298
Chunk : "base" ,
299
- Expectation : "550ccae3705ce9627190644ef89f404f94b8d6f9d13d8df537ca66080dd326b2" ,
299
+ Expectation : map [ string ] string { "base" : "02e46ef9c6d86deea6ffb67b6cd04a99e3600bb8d2c01f60359ed7a1ba2ed295" } ,
300
300
},
301
301
{
302
302
Name : "base with tests should not have same hash as no tests if tests included" ,
@@ -316,7 +316,7 @@ func TestProjectChunk_hash(t *testing.T) {
316
316
Base : "" ,
317
317
BaseRef : "" ,
318
318
Chunk : "base" ,
319
- Expectation : "a557385d3e9d012dd179eaf7569850107c4af1adf8d99eb0fc402727827fab14" ,
319
+ Expectation : map [ string ] string { "base" : "9548234ad00c759a443539823a08af24a7e4cafcda34956cfcf89e005d1582b1" } ,
320
320
IncludeTests : true ,
321
321
},
322
322
{
@@ -337,7 +337,7 @@ func TestProjectChunk_hash(t *testing.T) {
337
337
Base : "" ,
338
338
BaseRef : "" ,
339
339
Chunk : "base" ,
340
- Expectation : "cf686202a95f644d3767667c6172b6b29c4d225db23bcc8d17aa4bdb42224b58" ,
340
+ Expectation : map [ string ] string { "base" : "e1edf60be9936de9a8e53d56b3d3caab266a85910dd301f387f340da4ac986db" } ,
341
341
IncludeTests : true ,
342
342
},
343
343
{
@@ -358,14 +358,14 @@ func TestProjectChunk_hash(t *testing.T) {
358
358
Base : "" ,
359
359
BaseRef : "" ,
360
360
Chunk : "base" ,
361
- Expectation : "550ccae3705ce9627190644ef89f404f94b8d6f9d13d8df537ca66080dd326b2" ,
361
+ Expectation : map [ string ] string { "base" : "02e46ef9c6d86deea6ffb67b6cd04a99e3600bb8d2c01f60359ed7a1ba2ed295" } ,
362
362
},
363
363
{
364
364
Name : "chunk only no tests" ,
365
365
Base : "chunks" ,
366
366
BaseRef : "" ,
367
367
Chunk : "foobar" ,
368
- Expectation : "fee0ceb7e0e5dd96ea24167ff3dc7fb31c88877cf165a37b1b35e6c7072e0993" ,
368
+ Expectation : map [ string ] string { "foobar" : "6991b773b801a8eafb74dd95d5544d499ba1da5c9a677dbc5084dd6a03e5affa" } ,
369
369
FS : map [string ]* fstest.MapFile {
370
370
"chunks/foobar/Dockerfile" : {
371
371
Data : []byte ("FROM ubuntu" ),
@@ -377,7 +377,7 @@ func TestProjectChunk_hash(t *testing.T) {
377
377
Base : "chunks" ,
378
378
BaseRef : "" ,
379
379
Chunk : "foobar" ,
380
- Expectation : "fee0ceb7e0e5dd96ea24167ff3dc7fb31c88877cf165a37b1b35e6c7072e0993" ,
380
+ Expectation : map [ string ] string { "foobar" : "6991b773b801a8eafb74dd95d5544d499ba1da5c9a677dbc5084dd6a03e5affa" } ,
381
381
FS : map [string ]* fstest.MapFile {
382
382
"chunks/foobar/Dockerfile" : {
383
383
Data : []byte ("FROM ubuntu" ),
@@ -401,7 +401,7 @@ func TestProjectChunk_hash(t *testing.T) {
401
401
Base : "chunks" ,
402
402
BaseRef : "" ,
403
403
Chunk : "foobar" ,
404
- Expectation : "f9e18ae354d33f5a9c317c89d7251ad323fb49b650031d5d5563a9693bcf2ae9" ,
404
+ Expectation : map [ string ] string { "foobar" : "7eac1330365e4e8c08c95a343380693b435e00f6d9246f47e7194ce3d749d489" } ,
405
405
FS : map [string ]* fstest.MapFile {
406
406
"chunks/foobar/Dockerfile" : {
407
407
Data : []byte ("FROM ubuntu" ),
@@ -416,6 +416,32 @@ func TestProjectChunk_hash(t *testing.T) {
416
416
command: ["pwd"]
417
417
assert:
418
418
- "status == 0"
419
+ ` ),
420
+ },
421
+ },
422
+ IncludeTests : true ,
423
+ },
424
+ {
425
+ Name : "chunk with variants should produce different hashes" ,
426
+ Base : "chunks" ,
427
+ BaseRef : "" ,
428
+ Chunk : "foobar" ,
429
+ Expectation : map [string ]string {
430
+ "foobar:1.16.3" : "1d6cf828c405001a5dcbf034c638dace2ae5ab20d27c6c33519a7f6b5ca3eae6" ,
431
+ "foobar:1.16.4" : "983b53b4df52485fe2c4a7cdc005b957d03909459d4a10de3463cf4facf45ee2" ,
432
+ },
433
+ FS : map [string ]* fstest.MapFile {
434
+ "chunks/foobar/Dockerfile" : {
435
+ Data : []byte ("FROM ubuntu" ),
436
+ },
437
+ "chunks/foobar/chunk.yaml" : {
438
+ Data : []byte (`variants:
439
+ - name: "1.16.3"
440
+ args:
441
+ GO_VERSION: 1.16.3
442
+ - name: "1.16.4"
443
+ args:
444
+ GO_VERSION: 1.16.4
419
445
` ),
420
446
},
421
447
},
@@ -430,16 +456,17 @@ func TestProjectChunk_hash(t *testing.T) {
430
456
t .Errorf ("could not load chunks: %v" , err )
431
457
return
432
458
}
433
- if len ( chks ) != 1 {
434
- t . Error ( "can only test 1 chunk prohect" )
435
- return
436
- }
437
- chk := chks [ 0 ]
438
- act , err := chk . hash ( test . BaseRef , ! test . IncludeTests )
439
- if err != nil {
440
- t . Errorf ( "could not compute hash: %v" , err )
441
- return
459
+
460
+ act := make ( map [ string ] string , len ( chks ) )
461
+ for _ , chk := range chks {
462
+ hash , err := chk . hash ( test . BaseRef , ! test . IncludeTests )
463
+ if err != nil {
464
+ t . Errorf ( "could not compute hash: %v" , err )
465
+ return
466
+ }
467
+ act [ chk . Name ] = hash
442
468
}
469
+
443
470
if diff := cmp .Diff (test .Expectation , act ); diff != "" {
444
471
t .Errorf ("hash() mismatch (-want +got):\n %s" , diff )
445
472
}
0 commit comments