Updated tests
This commit is contained in:
parent
282f8abbee
commit
459ddffb3c
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
@ -23,37 +23,6 @@ import (
|
||||||
"testing"
|
"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) {
|
func Test_EnvExecute(t *testing.T) {
|
||||||
cfg := &v1.Config{
|
cfg := &v1.Config{
|
||||||
Env: []string{
|
Env: []string{
|
||||||
|
|
|
||||||
|
|
@ -123,12 +123,15 @@ func Dependencies(index int, stages []instructions.Stage, buildArgs *BuildArgs)
|
||||||
if err := util.UpdateConfigEnv(c.Env, &imageConfig.Config, replacementEnvs); err != nil {
|
if err := util.UpdateConfigEnv(c.Env, &imageConfig.Config, replacementEnvs); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
case *instructions.ArgCommand:
|
||||||
|
buildArgs.AddArg(c.Key, c.Value)
|
||||||
case *instructions.CopyCommand:
|
case *instructions.CopyCommand:
|
||||||
if c.From != strconv.Itoa(index) {
|
if c.From != strconv.Itoa(index) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// First, resolve any environment replacement
|
// 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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,48 @@ func Test_Dependencies(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for index := range stages {
|
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)
|
testutil.CheckErrorAndDeepEqual(t, false, err, expectedDependencies[index], actualDeps)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2018 Google LLC
|
Copyright 2018 Google LLC
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue