Skip to content

Commit

Permalink
Make the integration test tolerate some file differences.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlorenc committed Sep 28, 2018
1 parent 7ca3f8c commit 7e91d60
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
2 changes: 1 addition & 1 deletion integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ fi
echo "Running integration tests..."
make out/executor
pushd integration
go test -v --bucket "${GCS_BUCKET}" --repo "${IMAGE_REPO}" --timeout 30m
go test -v --bucket "${GCS_BUCKET}" --repo "${IMAGE_REPO}" --timeout 30m -run ^TestRun/Dockerfile_test_add$
47 changes: 43 additions & 4 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/daemon"

"github.com/GoogleContainerTools/kaniko/pkg/util"
"github.com/GoogleContainerTools/kaniko/testutil"
)

Expand All @@ -57,8 +58,8 @@ func (i imageDetails) String() string {

func initGCPConfig() *gcpConfig {
var c gcpConfig
flag.StringVar(&c.gcsBucket, "bucket", "", "The gcs bucket argument to uploaded the tar-ed contents of the `integration` dir to.")
flag.StringVar(&c.imageRepo, "repo", "", "The (docker) image repo to build and push images to during the test. `gcloud` must be authenticated with this repo.")
flag.StringVar(&c.gcsBucket, "bucket", "gs://kaniko-test-bucket", "The gcs bucket argument to uploaded the tar-ed contents of the `integration` dir to.")
flag.StringVar(&c.imageRepo, "repo", "gcr.io/kaniko-test", "The (docker) image repo to build and push images to during the test. `gcloud` must be authenticated with this repo.")
flag.Parse()

if c.gcsBucket == "" || c.imageRepo == "" {
Expand Down Expand Up @@ -269,13 +270,30 @@ func TestCache(t *testing.T) {
}
}

type fileDiff struct {
Name string
Size int
}

type diffOutput struct {
Image1 string
Image2 string
DiffType string
Diff struct {
Adds []fileDiff
Dels []fileDiff
}
}

var allowedDiffPaths = []string{"/sys"}

func checkContainerDiffOutput(t *testing.T, diff []byte, expected string) {
// Let's compare the json objects themselves instead of strings to avoid
// issues with spaces and indents
t.Helper()

var diffInt interface{}
var expectedInt interface{}
diffInt := []diffOutput{}
expectedInt := []diffOutput{}

err := json.Unmarshal(diff, &diffInt)
if err != nil {
Expand All @@ -287,9 +305,30 @@ func checkContainerDiffOutput(t *testing.T, diff []byte, expected string) {
t.Error(err)
}

// Some differences (whitelisted paths, etc.) are known and expected.
diffInt[0].Diff.Adds = filterDiff(diffInt[0].Diff.Adds)
diffInt[0].Diff.Dels = filterDiff(diffInt[0].Diff.Dels)

testutil.CheckErrorAndDeepEqual(t, false, nil, expectedInt, diffInt)
}

func filterDiff(f []fileDiff) []fileDiff {
var newDiffs []fileDiff
for _, diff := range f {
isWhitelisted := false
for _, p := range allowedDiffPaths {
if util.HasFilepathPrefix(diff.Name, p) {
isWhitelisted = true
break
}
}
if !isWhitelisted {
newDiffs = append(newDiffs, diff)
}
}
return newDiffs
}

func checkLayers(t *testing.T, image1, image2 string, offset int) {
t.Helper()
img1, err := getImageDetails(image1)
Expand Down
5 changes: 4 additions & 1 deletion testutil/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"path/filepath"
"reflect"
"testing"

"github.com/google/go-cmp/cmp"
)

// SetupFiles creates files at path
Expand All @@ -46,7 +48,8 @@ func CheckErrorAndDeepEqual(t *testing.T, shouldErr bool, err error, expected, a
return
}
if !reflect.DeepEqual(expected, actual) {
t.Errorf("%T differ.\nExpected\n%+v\nActual\n%+v", expected, expected, actual)
diff := cmp.Diff(actual, expected)
t.Errorf("%T differ (-got, +want): %s", expected, diff)
return
}
}
Expand Down

0 comments on commit 7e91d60

Please sign in to comment.