Skip to content

Commit

Permalink
refact(buildGraph): new internal test to check the assignement of fil…
Browse files Browse the repository at this point in the history
…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.
42 changes: 40 additions & 2 deletions pkg/dib/generate_dag_internal_test.go
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)
}
})
}

0 comments on commit a272181

Please sign in to comment.