Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Priya Wadhwa committed Jul 9, 2018
1 parent 96cad80 commit 5c0ce30
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 29 deletions.
1 change: 0 additions & 1 deletion pkg/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 3 additions & 5 deletions pkg/snapshot/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 0 additions & 5 deletions pkg/util/command_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
15 changes: 0 additions & 15 deletions pkg/util/fs_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 8 additions & 3 deletions pkg/util/fs_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
})
}
Expand Down

0 comments on commit 5c0ce30

Please sign in to comment.