Updated tests

This commit is contained in:
Priya Wadhwa 2018-05-11 16:16:11 -07:00
parent 282f8abbee
commit 459ddffb3c
No known key found for this signature in database
GPG Key ID: 0D0DAFD8F7AA73AE
5 changed files with 61 additions and 33 deletions

View File

@ -0,0 +1,12 @@
[
{
"Image1": "gcr.io/kaniko-test/docker-test-scratch:latest",
"Image2": "gcr.io/kaniko-test/kaniko-test-scratch:latest",
"DiffType": "File",
"Diff": {
"Adds": null,
"Dels": null,
"Mods": null
}
}
]

View File

@ -23,37 +23,6 @@ import (
"testing"
)
func TestUpdateEnvConfig(t *testing.T) {
cfg := &v1.Config{
Env: []string{
"PATH=/path/to/dir",
"hey=hey",
},
}
newEnvs := []instructions.KeyValuePair{
{
Key: "foo",
Value: "foo2",
},
{
Key: "PATH",
Value: "/new/path/",
},
{
Key: "foo",
Value: "newfoo",
},
}
expectedEnvArray := []string{
"PATH=/new/path/",
"hey=hey",
"foo=newfoo",
}
updateConfigEnv(newEnvs, cfg)
testutil.CheckErrorAndDeepEqual(t, false, nil, expectedEnvArray, cfg.Env)
}
func Test_EnvExecute(t *testing.T) {
cfg := &v1.Config{
Env: []string{

View File

@ -123,12 +123,15 @@ func Dependencies(index int, stages []instructions.Stage, buildArgs *BuildArgs)
if err := util.UpdateConfigEnv(c.Env, &imageConfig.Config, replacementEnvs); err != nil {
return nil, err
}
case *instructions.ArgCommand:
buildArgs.AddArg(c.Key, c.Value)
case *instructions.CopyCommand:
if c.From != strconv.Itoa(index) {
continue
}
// First, resolve any environment replacement
resolvedEnvs, err := util.ResolveEnvironmentReplacementList(c.SourcesAndDest, imageConfig.Config.Env, true)
replacementEnvs := buildArgs.ReplacementEnvs(imageConfig.Config.Env)
resolvedEnvs, err := util.ResolveEnvironmentReplacementList(c.SourcesAndDest, replacementEnvs, true)
if err != nil {
return nil, err
}

View File

@ -89,7 +89,48 @@ func Test_Dependencies(t *testing.T) {
}
for index := range stages {
actualDeps, err := Dependencies(index, stages)
buildArgs := NewBuildArgs([]string{})
actualDeps, err := Dependencies(index, stages, buildArgs)
testutil.CheckErrorAndDeepEqual(t, false, err, expectedDependencies[index], actualDeps)
}
}
func Test_DependenciesWithArg(t *testing.T) {
testDir, err := ioutil.TempDir("", "")
if err != nil {
t.Fatal(err)
}
helloPath := filepath.Join(testDir, "hello")
if err := os.Mkdir(helloPath, 0755); err != nil {
t.Fatal(err)
}
dockerfile := fmt.Sprintf(`
FROM scratch
COPY %s %s
FROM scratch AS second
ARG hienv
COPY a b
COPY --from=0 /$hienv %s /hi2/
`, helloPath, helloPath, testDir)
stages, err := Parse([]byte(dockerfile))
if err != nil {
t.Fatal(err)
}
expectedDependencies := [][]string{
{
helloPath,
testDir,
},
nil,
}
buildArgs := NewBuildArgs([]string{fmt.Sprintf("hienv=%s", helloPath)})
for index := range stages {
actualDeps, err := Dependencies(index, stages, buildArgs)
testutil.CheckErrorAndDeepEqual(t, false, err, expectedDependencies[index], actualDeps)
}
}

View File

@ -1,9 +1,12 @@
/*
Copyright 2018 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.