-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refact(buildGraph): new internal test to check the assignement of fil…
…es to nodes
- Loading branch information
Antoine Gelloz
committed
Oct 9, 2024
1 parent
0e6bb2b
commit a272181
Showing
1 changed file
with
40 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,47 @@ | ||
package dib | ||
|
||
import "testing" | ||
import ( | ||
"testing" | ||
|
||
"github.com/davecgh/go-spew/spew" | ||
"github.com/radiofrance/dib/pkg/dag" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
const ( | ||
buildPath = "../../test/fixtures/docker" | ||
registryPrefix = "eu.gcr.io/my-test-repository" | ||
) | ||
|
||
func Test_buildGraph(t *testing.T) { | ||
t.Parallel() | ||
|
||
// Implement me. | ||
graph, err := buildGraph(buildPath, registryPrefix) | ||
require.NoError(t, err) | ||
graph.WalkInDepth(func(node *dag.Node) { | ||
switch node.Image.ShortName { | ||
case "bullseye": | ||
require.Len(t, node.Files, 5, spew.Sdump(node.Files)) | ||
assert.Contains(t, node.Files, buildPath+"/bullseye/Dockerfile") | ||
assert.Contains(t, node.Files, buildPath+"/bullseye/external-parent/Dockerfile") | ||
assert.Contains(t, node.Files, buildPath+"/bullseye/multistage/Dockerfile") | ||
assert.Contains(t, node.Files, buildPath+"/bullseye/skipbuild/Dockerfile") | ||
assert.Contains(t, node.Files, buildPath+"/bullseye/sub-image/Dockerfile") | ||
case "kaniko": | ||
require.Len(t, node.Files, 1, spew.Sdump(node.Files)) | ||
assert.Contains(t, node.Files, buildPath+"/bullseye/external-parent/Dockerfile") | ||
case "multistage": | ||
require.Len(t, node.Files, 1, spew.Sdump(node.Files)) | ||
assert.Contains(t, node.Files, buildPath+"/bullseye/multistage/Dockerfile") | ||
case "skipbuild": | ||
require.Len(t, node.Files, 1, spew.Sdump(node.Files)) | ||
assert.Contains(t, node.Files, buildPath+"/bullseye/skipbuild/Dockerfile") | ||
case "sub-image": | ||
require.Len(t, node.Files, 1, spew.Sdump(node.Files)) | ||
assert.Contains(t, node.Files, buildPath+"/bullseye/sub-image/Dockerfile") | ||
default: | ||
t.Errorf("unexpected image: %s", node.Image.ShortName) | ||
} | ||
}) | ||
} |