Skip to content

Commit

Permalink
Chore: docker unit test
Browse files Browse the repository at this point in the history
* docker test
  • Loading branch information
Martin Olsiak authored and squakez committed Mar 24, 2023
1 parent 457f835 commit 3062e68
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions pkg/util/docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ import (

func TestCreateBaseImageDockerFile(t *testing.T) {

dockerfileExists, _ := util.FileExists("Dockerfile")
dockerfileExists, _ := util.FileExists("/tmp/Dockerfile")
if dockerfileExists {
os.Remove("Dockerfile")
os.Remove("/tmp/Dockerfile")
}

dockerFile := []string{}
dockerFile = append(dockerFile, FROM(defaults.BaseImage()))
dockerFile = append(dockerFile, RUNMavenInstall())
expected := strings.Join(dockerFile, "\n")

BaseWorkingDirectory = ""
BaseWorkingDirectory = "/tmp/"

err := CreateBaseImageDockerFile()
assert.Nil(t, err)
Expand All @@ -52,14 +52,15 @@ func TestCreateBaseImageDockerFile(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, expected, string(c))

os.Remove("/tmp/Dockerfile")
}

func TestCreateIntegrationImageDockerFile(t *testing.T) {
dockerfileExists, _ := util.FileExists("Dockerfile")
dockerfileExists, _ := util.FileExists("/tmp/Dockerfile")
if dockerfileExists {
os.Remove("Dockerfile")
os.Remove("/tmp/Dockerfile")
}

IntegrationWorkingDirectory = "/tmp/"
var cmd exec.Cmd
cmd.Path = "test"
cmd.Env = []string{"key=value"}
Expand Down Expand Up @@ -92,24 +93,23 @@ func TestCreateIntegrationImageDockerFile(t *testing.T) {
err := CreateIntegrationImageDockerFile(&cmd, false)
assert.Nil(t, err)

c, err := util.ReadFile("Dockerfile")
c, err := util.ReadFile("/tmp/Dockerfile")
assert.Nil(t, err)
assert.Equal(t, expected, string(c))

os.Remove("Dockerfile")
os.Remove("/tmp/Dockerfile")

expected = strings.Join(dockerFile2, "\n")

err = CreateIntegrationImageDockerFile(&cmd, true)
assert.Nil(t, err)

c, err = util.ReadFile("Dockerfile")
c, err = util.ReadFile("/tmp/Dockerfile")
assert.Nil(t, err)
assert.Equal(t, expected, string(c))

os.Remove("Dockerfile")
os.Remove("/tmp/Dockerfile")

CreateBaseImageDockerFile()
}

func TestContainerizeFilePaths(t *testing.T) {
Expand Down

0 comments on commit 3062e68

Please sign in to comment.