Skip to content

Commit 5c1f783

Browse files
committed
Fix unit tests
1 parent 87d48f9 commit 5c1f783

File tree

1 file changed

+45
-18
lines changed

1 file changed

+45
-18
lines changed

pkg/dazzle/project_test.go

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ func TestProjectChunk_hash(t *testing.T) {
264264
BaseRef string
265265
Chunk string
266266
IncludeTests bool
267-
Expectation string
267+
Expectation map[string]string
268268
}{
269269
{
270270
Name: "base only no tests",
@@ -276,7 +276,7 @@ func TestProjectChunk_hash(t *testing.T) {
276276
Base: "",
277277
BaseRef: "",
278278
Chunk: "base",
279-
Expectation: "550ccae3705ce9627190644ef89f404f94b8d6f9d13d8df537ca66080dd326b2",
279+
Expectation: map[string]string{"base": "02e46ef9c6d86deea6ffb67b6cd04a99e3600bb8d2c01f60359ed7a1ba2ed295"},
280280
},
281281
{
282282
Name: "base with other tests should have same hash as no tests",
@@ -296,7 +296,7 @@ func TestProjectChunk_hash(t *testing.T) {
296296
Base: "",
297297
BaseRef: "",
298298
Chunk: "base",
299-
Expectation: "550ccae3705ce9627190644ef89f404f94b8d6f9d13d8df537ca66080dd326b2",
299+
Expectation: map[string]string{"base": "02e46ef9c6d86deea6ffb67b6cd04a99e3600bb8d2c01f60359ed7a1ba2ed295"},
300300
},
301301
{
302302
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) {
316316
Base: "",
317317
BaseRef: "",
318318
Chunk: "base",
319-
Expectation: "a557385d3e9d012dd179eaf7569850107c4af1adf8d99eb0fc402727827fab14",
319+
Expectation: map[string]string{"base": "9548234ad00c759a443539823a08af24a7e4cafcda34956cfcf89e005d1582b1"},
320320
IncludeTests: true,
321321
},
322322
{
@@ -337,7 +337,7 @@ func TestProjectChunk_hash(t *testing.T) {
337337
Base: "",
338338
BaseRef: "",
339339
Chunk: "base",
340-
Expectation: "cf686202a95f644d3767667c6172b6b29c4d225db23bcc8d17aa4bdb42224b58",
340+
Expectation: map[string]string{"base": "e1edf60be9936de9a8e53d56b3d3caab266a85910dd301f387f340da4ac986db"},
341341
IncludeTests: true,
342342
},
343343
{
@@ -358,14 +358,14 @@ func TestProjectChunk_hash(t *testing.T) {
358358
Base: "",
359359
BaseRef: "",
360360
Chunk: "base",
361-
Expectation: "550ccae3705ce9627190644ef89f404f94b8d6f9d13d8df537ca66080dd326b2",
361+
Expectation: map[string]string{"base": "02e46ef9c6d86deea6ffb67b6cd04a99e3600bb8d2c01f60359ed7a1ba2ed295"},
362362
},
363363
{
364364
Name: "chunk only no tests",
365365
Base: "chunks",
366366
BaseRef: "",
367367
Chunk: "foobar",
368-
Expectation: "fee0ceb7e0e5dd96ea24167ff3dc7fb31c88877cf165a37b1b35e6c7072e0993",
368+
Expectation: map[string]string{"foobar": "6991b773b801a8eafb74dd95d5544d499ba1da5c9a677dbc5084dd6a03e5affa"},
369369
FS: map[string]*fstest.MapFile{
370370
"chunks/foobar/Dockerfile": {
371371
Data: []byte("FROM ubuntu"),
@@ -377,7 +377,7 @@ func TestProjectChunk_hash(t *testing.T) {
377377
Base: "chunks",
378378
BaseRef: "",
379379
Chunk: "foobar",
380-
Expectation: "fee0ceb7e0e5dd96ea24167ff3dc7fb31c88877cf165a37b1b35e6c7072e0993",
380+
Expectation: map[string]string{"foobar": "6991b773b801a8eafb74dd95d5544d499ba1da5c9a677dbc5084dd6a03e5affa"},
381381
FS: map[string]*fstest.MapFile{
382382
"chunks/foobar/Dockerfile": {
383383
Data: []byte("FROM ubuntu"),
@@ -401,7 +401,7 @@ func TestProjectChunk_hash(t *testing.T) {
401401
Base: "chunks",
402402
BaseRef: "",
403403
Chunk: "foobar",
404-
Expectation: "f9e18ae354d33f5a9c317c89d7251ad323fb49b650031d5d5563a9693bcf2ae9",
404+
Expectation: map[string]string{"foobar": "7eac1330365e4e8c08c95a343380693b435e00f6d9246f47e7194ce3d749d489"},
405405
FS: map[string]*fstest.MapFile{
406406
"chunks/foobar/Dockerfile": {
407407
Data: []byte("FROM ubuntu"),
@@ -416,6 +416,32 @@ func TestProjectChunk_hash(t *testing.T) {
416416
command: ["pwd"]
417417
assert:
418418
- "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
419445
`),
420446
},
421447
},
@@ -430,16 +456,17 @@ func TestProjectChunk_hash(t *testing.T) {
430456
t.Errorf("could not load chunks: %v", err)
431457
return
432458
}
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
442468
}
469+
443470
if diff := cmp.Diff(test.Expectation, act); diff != "" {
444471
t.Errorf("hash() mismatch (-want +got):\n%s", diff)
445472
}

0 commit comments

Comments
 (0)