From 5c0ce3045a0f4197991fa43d52fd830ad8d6ec91 Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Mon, 9 Jul 2018 16:25:04 -0700 Subject: [PATCH] fix unit tests --- pkg/executor/executor.go | 1 - pkg/snapshot/snapshot_test.go | 8 +++----- pkg/util/command_util.go | 5 ----- pkg/util/fs_util.go | 15 --------------- pkg/util/fs_util_test.go | 11 ++++++++--- 5 files changed, 11 insertions(+), 29 deletions(-) diff --git a/pkg/executor/executor.go b/pkg/executor/executor.go index 8cefce17af..18a6e1fb06 100644 --- a/pkg/executor/executor.go +++ b/pkg/executor/executor.go @@ -228,7 +228,6 @@ func saveStageDependencies(index int, stages []instructions.Stage, buildArgs *do dependencies, err := dockerfile.Dependencies(index, stages, buildArgs) logrus.Infof("saving dependencies %s", dependencies) if err != nil { - logrus.Info("returning err from getting dependencies") return err } if len(dependencies) == 0 { diff --git a/pkg/snapshot/snapshot_test.go b/pkg/snapshot/snapshot_test.go index f8f3c01618..934e862d94 100644 --- a/pkg/snapshot/snapshot_test.go +++ b/pkg/snapshot/snapshot_test.go @@ -38,9 +38,8 @@ func TestSnapshotFileChange(t *testing.T) { } // Make some changes to the filesystem newFiles := map[string]string{ - "foo": "newbaz1", - "bar/bat": "baz", - "kaniko/bat": "bat", + "foo": "newbaz1", + "bar/bat": "baz", } if err := testutil.SetupFiles(testDir, newFiles); err != nil { t.Fatalf("Error setting up fs: %s", err) @@ -135,8 +134,7 @@ func TestSnapshotFiles(t *testing.T) { } // Make some changes to the filesystem newFiles := map[string]string{ - "foo": "newbaz1", - "kaniko/file": "bat", + "foo": "newbaz1", } if err := testutil.SetupFiles(testDir, newFiles); err != nil { t.Fatalf("Error setting up fs: %s", err) diff --git a/pkg/util/command_util.go b/pkg/util/command_util.go index 7b3a57e330..8d4bb37155 100644 --- a/pkg/util/command_util.go +++ b/pkg/util/command_util.go @@ -89,25 +89,20 @@ func ContainsWildcards(paths []string) bool { // It returns a list of resolved sources func ResolveSources(srcsAndDest instructions.SourcesAndDest, root string) ([]string, error) { srcs := srcsAndDest[:len(srcsAndDest)-1] - logrus.Infof("looking at srcs %s", srcs) // If sources contain wildcards, we first need to resolve them to actual paths if ContainsWildcards(srcs) { logrus.Debugf("Resolving srcs %v...", srcs) files, err := RelativeFiles("", root) if err != nil { - logrus.Info("error getting relative files") return nil, err } srcs, err = matchSources(srcs, files) - logrus.Infof("srcs after matching: %s", srcs) if err != nil { - logrus.Info("error matching sources") return nil, err } logrus.Debugf("Resolved sources to %v", srcs) } // Check to make sure the sources are valid - logrus.Infof("sources %s are not valid", srcs) return srcs, IsSrcsValid(srcsAndDest, srcs, root) } diff --git a/pkg/util/fs_util.go b/pkg/util/fs_util.go index e37ade0bcd..7667c68c0d 100644 --- a/pkg/util/fs_util.go +++ b/pkg/util/fs_util.go @@ -233,21 +233,6 @@ func extractFile(dest string, hdr *tar.Header, tr io.Reader) error { return nil } -// func PathInWhitelist(path, directory string) bool { -// for _, c := range constants.KanikoBuildFiles { -// if path == c { -// return false -// } -// } -// for _, d := range whitelist { -// dirPath := filepath.Join(directory, d) -// if HasFilepathPrefix(path, dirPath) { -// return true -// } -// } -// return false -// } - func checkWhiteouts(path string, whiteouts map[string]struct{}) bool { // Don't add the file if it or it's directory are whited out. if _, ok := whiteouts[path]; ok { diff --git a/pkg/util/fs_util_test.go b/pkg/util/fs_util_test.go index 404a0f0886..21ff3a7661 100644 --- a/pkg/util/fs_util_test.go +++ b/pkg/util/fs_util_test.go @@ -216,7 +216,7 @@ func Test_checkWhiteouts(t *testing.T) { } } -func Test_checkWhitelist(t *testing.T) { +func Test_CheckWhitelist(t *testing.T) { type args struct { path string whitelist []string @@ -261,8 +261,13 @@ func Test_checkWhitelist(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := checkWhitelist(tt.args.path, tt.args.whitelist); got != tt.want { - t.Errorf("checkWhitelist() = %v, want %v", got, tt.want) + original := whitelist + defer func() { + whitelist = original + }() + whitelist = tt.args.whitelist + if got := CheckWhitelist(tt.args.path); got != tt.want { + t.Errorf("CheckWhitelist() = %v, want %v", got, tt.want) } }) }