Skip to content

Commit

Permalink
Force setting a component name when copying example Devfiles
Browse files Browse the repository at this point in the history
This way, we won't forget about this in the future.
  • Loading branch information
rm3l committed May 22, 2023
1 parent 690f056 commit af2aaca
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 76 deletions.
4 changes: 2 additions & 2 deletions tests/e2escenarios/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ var _ = Describe("E2E Test", func() {
helper.CopyExampleDevFile(
filepath.Join("source", "devfiles", "nodejs", "devfile-deploy.yaml"),
path.Join(commonVar.Context, "devfile.yaml"),
helper.DevfileMetadataNameSetter(componentName))
componentName)

stdout = helper.Cmd("odo", "deploy").AddEnv("PODMAN_CMD=echo").ShouldPass().Out()
Expect(stdout).To(ContainSubstring("Your Devfile has been successfully deployed"))
Expand Down Expand Up @@ -269,7 +269,7 @@ var _ = Describe("E2E Test", func() {
helper.CopyExampleDevFile(
filepath.Join("source", "devfiles", "springboot", "devfile-deploy.yaml"),
path.Join(commonVar.Context, "devfile.yaml"),
helper.DevfileMetadataNameSetter(componentName))
componentName)

stdout = helper.Cmd("odo", "deploy").AddEnv("PODMAN_CMD=echo").ShouldPass().Out()
Expect(stdout).To(ContainSubstring("Your Devfile has been successfully deployed"))
Expand Down
14 changes: 9 additions & 5 deletions tests/helper/helper_filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ func GetExamplePath(args ...string) string {
}

// CopyExampleDevFile copies an example devfile from tests/examples/source/devfiles/<componentName>/devfile.yaml into targetDst.
// The Devfile updaters allow to perform operations against the target Devfile, like updating the component name (via DevfileMetadataNameSetter) or
// removing the component name (via DevfileMetadataNameRemover).
func CopyExampleDevFile(devfilePath, targetDst string, devfileUpdaters ...DevfileUpdater) {
// If newName is not empty, it will replace the component name in the target Devfile.
// The Devfile updaters allow to perform operations against the target Devfile, like removing the component name (via DevfileMetadataNameRemover).
func CopyExampleDevFile(devfilePath, targetDst string, newName string, updaters ...DevfileUpdater) {
// filename of this file
_, filename, _, _ := runtime.Caller(0)
// path to the examples directory
Expand All @@ -155,9 +155,13 @@ func CopyExampleDevFile(devfilePath, targetDst string, devfileUpdaters ...Devfil

err = dfutil.CopyFile(src, targetDst, info)
Expect(err).NotTo(HaveOccurred())
if len(devfileUpdaters) != 0 {
UpdateDevfileContent(targetDst, devfileUpdaters)

var devfileUpdaters []DevfileUpdater
if newName != "" {
devfileUpdaters = append(devfileUpdaters, DevfileMetadataNameSetter(newName))
}
devfileUpdaters = append(devfileUpdaters, updaters...)
UpdateDevfileContent(targetDst, devfileUpdaters)
}

// FileShouldContainSubstring check if file contains subString
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/cmd_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ var _ = Describe("odo delete command tests", func() {
helper.CopyExampleDevFile(
filepath.Join("source", "devfiles", "nodejs", "devfile.yaml"),
path.Join(commonVar.Context, "devfile.yaml"),
helper.DevfileMetadataNameSetter(cmpName))
cmpName)
if withDotOdoDir {
helper.MakeDir(filepath.Join(commonVar.Context, util.DotOdoDirectory))
}
Expand Down Expand Up @@ -735,7 +735,7 @@ var _ = Describe("odo delete command tests", func() {
helper.CopyExampleDevFile(
filepath.Join("source", "devfiles", "nodejs", "devfile-deploy-exec.yaml"),
path.Join(commonVar.Context, "devfile.yaml"),
helper.DevfileMetadataNameSetter(cmpName))
cmpName)
helper.ReplaceString(filepath.Join(commonVar.Context, "devfile.yaml"), `image: registry.access.redhat.com/ubi8/nodejs-14:latest`, `image: registry.access.redhat.com/ubi8/nodejs-does-not-exist-14:latest`)
// We terminate after 5 seconds because the job should have been created by then and is bound to fail.
helper.Cmd("odo", "deploy").WithTerminate(5, nil).ShouldRun()
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/cmd_describe_component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ var _ = Describe("odo describe component command tests", func() {
helper.CopyExampleDevFile(
filepath.Join("source", "devfiles", "nodejs", ctx.devfile),
path.Join(commonVar.Context, "devfile.yaml"),
helper.DevfileMetadataNameSetter(componentName))
componentName)
helper.Cmd("odo", "deploy").AddEnv("PODMAN_CMD=echo").ShouldPass()
})
It(fmt.Sprintf("should show the %s in odo describe component output", ctx.title), func() {
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/cmd_dev_debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ var _ = Describe("odo dev debug command tests", func() {
helper.CopyExampleDevFile(
filepath.Join("source", "devfiles", "nodejs", "devfileCompositeRunAndDebug.yaml"),
filepath.Join(commonVar.Context, "devfile.yaml"),
helper.DevfileMetadataNameSetter(devfileCmpName))
devfileCmpName)
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context)
if devfileHandlerCtx.sourceHandler != nil {
devfileHandlerCtx.sourceHandler(commonVar.Context, devfileCmpName)
Expand Down Expand Up @@ -284,7 +284,7 @@ var _ = Describe("odo dev debug command tests", func() {
helper.CopyExampleDevFile(
filepath.Join("source", "devfiles", "nodejs", "devfile-composite-apply-commands.yaml"),
filepath.Join(commonVar.Context, "devfile.yaml"),
helper.DevfileMetadataNameSetter(cmpName))
cmpName)
session, sessionOut, _, ports, err = helper.StartDevMode(helper.DevSessionOpts{
EnvVars: []string{"PODMAN_CMD=echo"},
CmdlineArgs: []string{"--debug"},
Expand Down Expand Up @@ -371,7 +371,7 @@ var _ = Describe("odo dev debug command tests", func() {
helper.CopyExampleDevFile(
filepath.Join("source", "devfiles", "nodejs", "devfileCompositeBuildRunDebugInMultiContainersAndSharedVolume.yaml"),
filepath.Join(commonVar.Context, "devfile.yaml"),
helper.DevfileMetadataNameSetter(devfileCmpName))
devfileCmpName)
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context)
if devfileHandlerCtx.sourceHandler != nil {
devfileHandlerCtx.sourceHandler(commonVar.Context, devfileCmpName)
Expand Down Expand Up @@ -469,7 +469,7 @@ var _ = Describe("odo dev debug command tests", func() {
helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context)
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile-autobuild-deploybydefault.yaml"),
filepath.Join(commonVar.Context, "devfile.yaml"),
helper.DevfileMetadataNameSetter(cmpName))
cmpName)
})

When("running odo dev with some components not referenced in the Devfile", func() {
Expand Down
Loading

0 comments on commit af2aaca

Please sign in to comment.