1
0
mirror of https://github.com/openshift/source-to-image.git synced 2026-02-05 12:44:54 +01:00

Reduce usage of docker/docker

* Use moby/buildkit for dockerfile parsing
* Refactor TestConvertEnvironmentToDocker to be a true unit test.
This commit is contained in:
Adam Kaplan
2019-12-10 13:44:14 -05:00
parent 196a4ff45a
commit 2044e2993f
3 changed files with 18 additions and 27 deletions

View File

@@ -7,7 +7,7 @@ import (
"strings"
"testing"
"github.com/docker/docker/builder/dockerfile/parser"
"github.com/moby/buildkit/frontend/dockerfile/parser"
"github.com/openshift/source-to-image/pkg/api"
"github.com/openshift/source-to-image/pkg/docker"

View File

@@ -3,8 +3,6 @@ package scripts
import (
"testing"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/builder/dockerfile"
"github.com/openshift/source-to-image/pkg/api"
)
@@ -44,29 +42,21 @@ func equalArrayContents(a []string, b []string) bool {
}
func TestConvertEnvironmentToDocker(t *testing.T) {
testValues := []string{
"Value1",
"$Value1",
"${Value1}",
"`Value1`",
`"`,
inputEnv := api.EnvironmentList{
{Name: "FOO", Value: "BAR"},
{Name: "THIS", Value: "that"},
{Name: "DOLLAR", Value: "${value}"},
{Name: "QUOTE", Value: "\"quoted\""},
{Name: "BACKSLASH", Value: "windows\\path"},
}
var charValues []string
for ch := rune(32); ch < 127; ch++ {
charValues = append(charValues, "AB"+string(ch)+"CD", "AB\\"+string(ch)+"CD")
}
for _, testValue := range append(testValues, charValues...) {
list := api.EnvironmentList{{Name: "TEST", Value: testValue}}
converted := ConvertEnvironmentToDocker(list)
config, err := dockerfile.BuildFromConfig(&container.Config{}, []string{converted})
if err != nil {
t.Fatalf("Unexpected error building using Dockerfile contents %v: %v", converted, err)
}
if len(config.Env) != 1 {
t.Errorf("Unexpected result. Expected 1 environment variable, got config %#v", config)
}
if config.Env[0] != "TEST="+testValue {
t.Errorf("Unexpected result. Expected: %s=%#v -> %q -> %s=%v. Got: %#v", list[0].Name, testValue, converted, list[0].Name, testValue, config.Env[0])
}
expectedOutput := `ENV FOO="BAR" \
THIS="that" \
DOLLAR="\${value}" \
QUOTE="\"quoted\"" \
BACKSLASH="windows\\path"
`
output := ConvertEnvironmentToDocker(inputEnv)
if output != expectedOutput {
t.Errorf("Expected environment\n%s\ngot\n%s", expectedOutput, output)
}
}

View File

@@ -11,7 +11,8 @@ import (
"strings"
"testing"
"github.com/docker/docker/builder/dockerfile/parser"
"github.com/moby/buildkit/frontend/dockerfile/parser"
"github.com/openshift/source-to-image/pkg/api"
"github.com/openshift/source-to-image/pkg/build"
"github.com/openshift/source-to-image/pkg/build/strategies"