2021-09-26 11:37:53 -05:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
2021-09-27 14:01:14 -05:00
|
|
|
"context"
|
2021-09-26 11:37:53 -05:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2021-09-27 14:01:14 -05:00
|
|
|
func TestDocker(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
client, err := GetDockerClient(ctx)
|
|
|
|
assert.NoError(t, err)
|
2021-09-26 11:37:53 -05:00
|
|
|
|
2021-09-27 14:01:14 -05:00
|
|
|
dockerBuild := NewDockerBuildExecutor(NewDockerBuildExecutorInput{
|
|
|
|
ContextDir: "testdata",
|
|
|
|
ImageTag: "envmergetest",
|
|
|
|
})
|
2021-09-26 11:37:53 -05:00
|
|
|
|
2021-09-27 14:01:14 -05:00
|
|
|
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",
|
2021-09-26 11:37:53 -05:00
|
|
|
}
|
|
|
|
|
2021-09-27 14:01:14 -05:00
|
|
|
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)
|
2021-09-26 11:37:53 -05:00
|
|
|
}
|