Skip to content

Commit

Permalink
test: add test for extractFromImageEnv
Browse files Browse the repository at this point in the history
  • Loading branch information
hackercat committed Sep 27, 2021
1 parent ccde10e commit 01dd4d5
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
46 changes: 46 additions & 0 deletions pkg/container/docker_run_test.go
Original file line number Diff line number Diff line change
@@ -1 +1,47 @@
package container

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
)

func TestDocker(t *testing.T) {
ctx := context.Background()
client, err := GetDockerClient(ctx)
assert.NoError(t, err)

dockerBuild := NewDockerBuildExecutor(NewDockerBuildExecutorInput{
ContextDir: "testdata",
ImageTag: "envmergetest",
})

err = dockerBuild(ctx)
assert.NoError(t, err)

cr := &containerReference{
cli: client,
input: &NewContainerInput{
Image: "envmergetest",
},
}
env := map[string]string{
"PATH": "/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin",
"RANDOM_VAR": "WITH_VALUE",
"ANOTHER_VAR": "",
"CONFLICT_VAR": "I_EXIST_IN_MULTIPLE_PLACES",
}

envExecutor := cr.extractFromImageEnv(&env)
err = envExecutor(ctx)
assert.NoError(t, err)
assert.Equal(t, map[string]string{
"PATH": "/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin:/this/path/does/not/exists/anywhere:/this/either",
"RANDOM_VAR": "WITH_VALUE",
"ANOTHER_VAR": "",
"SOME_RANDOM_VAR": "",
"ANOTHER_ONE": "BUT_I_HAVE_VALUE",
"CONFLICT_VAR": "I_EXIST_IN_MULTIPLE_PLACES",
}, env)
}
5 changes: 5 additions & 0 deletions pkg/container/testdata/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM scratch
ENV PATH="/this/path/does/not/exists/anywhere:/this/either"
ENV SOME_RANDOM_VAR=""
ENV ANOTHER_ONE="BUT_I_HAVE_VALUE"
ENV CONFLICT_VAR="I_EXIST_ONLY_HERE"

0 comments on commit 01dd4d5

Please sign in to comment.