Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with build-images and deploy not working with Docker if optional buildContext field is not set in Devfile (#5600) #5657

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add unit test highlighting the issue
rm3l committed Apr 12, 2022
commit 71171ce5fe40c8de339c8e01b00a7f5ace0a3aa5
36 changes: 30 additions & 6 deletions pkg/devfile/image/docker_compatible_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package image

import (
"fmt"
"path/filepath"
"testing"

devfile "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
)

func TestGetShellCommand(t *testing.T) {
devfilePath := filepath.Join("home", "user", "project1")
tests := []struct {
name string
cmdName string
@@ -33,8 +35,9 @@ func TestGetShellCommand(t *testing.T) {
},
},
},
devfilePath: filepath.Join("home", "user", "project1"),
want: `cli build -t "registry.io/myimagename:tag" -f "` + filepath.Join("home", "user", "project1", "Dockerfile") + `" ${PROJECTS_ROOT}`,
devfilePath: devfilePath,
want: fmt.Sprintf(`cli build -t "registry.io/myimagename:tag" -f "%s" "${PROJECTS_ROOT}"`,
filepath.Join(devfilePath, "Dockerfile")),
},
{
name: "test 2",
@@ -54,8 +57,9 @@ func TestGetShellCommand(t *testing.T) {
},
},
},
devfilePath: filepath.Join("home", "user", "project1"),
want: `cli build -t "registry.io/myimagename:tag" -f "` + filepath.Join("home", "user", "project1", "Dockerfile") + `" ${PROJECTS_ROOT}`,
devfilePath: devfilePath,
want: fmt.Sprintf(`cli build -t "registry.io/myimagename:tag" -f "%s" "${PROJECTS_ROOT}"`,
filepath.Join(devfilePath, "Dockerfile")),
},
{
name: "test with args",
@@ -76,8 +80,28 @@ func TestGetShellCommand(t *testing.T) {
},
},
},
devfilePath: filepath.Join("home", "user", "project1"),
want: `cli build -t "registry.io/myimagename:tag" -f "` + filepath.Join("home", "user", "project1", "Dockerfile") + `" ${PROJECTS_ROOT} --flag value`,
devfilePath: devfilePath,
want: fmt.Sprintf(`cli build -t "registry.io/myimagename:tag" -f "%s" "${PROJECTS_ROOT}" --flag value`,
filepath.Join(devfilePath, "Dockerfile")),
},
{
name: "test with no build context in Devfile",
cmdName: "cli",
image: &devfile.ImageComponent{
Image: devfile.Image{
ImageName: "registry.io/myimagename:tag",
ImageUnion: devfile.ImageUnion{
Dockerfile: &devfile.DockerfileImage{
DockerfileSrc: devfile.DockerfileSrc{
Uri: "Dockerfile.rhel",
},
},
},
},
},
devfilePath: devfilePath,
want: fmt.Sprintf(`cli build -t "registry.io/myimagename:tag" -f "%s" "%s"`,
filepath.Join(devfilePath, "Dockerfile.rhel"), devfilePath),
},
}