Refactor odo exec integration tests + remove unused utils functions (#5049)

* Refactor odo exec integration tests + remove unused utils functions

* review
This commit is contained in:
Philippe Martin
2021-09-13 20:01:53 +02:00
committed by GitHub
parent e91b444049
commit c7e6424b2c
2 changed files with 44 additions and 350 deletions

View File

@@ -1,8 +1,9 @@
package devfile
import (
"path/filepath"
"github.com/openshift/odo/tests/helper"
"github.com/openshift/odo/tests/integration/devfile/utils"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@@ -25,25 +26,54 @@ var _ = Describe("odo devfile exec command tests", func() {
helper.CommonAfterEach(commonVar)
})
Context("When devfile exec command is executed", func() {
When("a component is created", func() {
BeforeEach(func() {
helper.Cmd("odo", "create", "nodejs", cmpName, "--context", commonVar.Context).ShouldPass()
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context)
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile.yaml"), filepath.Join(commonVar.Context, "devfile.yaml"))
It("should execute the given command successfully in the container", func() {
utils.ExecCommand(commonVar.Context, cmpName)
podName := commonVar.CliRunner.GetRunningPodNameByComponent(cmpName, commonVar.Project)
listDir := commonVar.CliRunner.ExecListDir(podName, commonVar.Project, "/projects")
Expect(listDir).To(ContainSubstring("blah.js"))
})
It("should error out when no command is given by the user", func() {
utils.ExecWithoutCommand(commonVar.Context, cmpName)
It("should error out", func() {
By("exec on a non deployed component", func() {
err := helper.Cmd("odo", "exec", "--context", commonVar.Context, "--", "touch", "/projects/blah.js").ShouldFail().Err()
Expect(err).To(ContainSubstring("doesn't exist on the cluster"))
})
By("exec with invalid devfile flag", func() {
err := helper.Cmd("odo", "exec", "--context", commonVar.Context, "--devfile", "invalid.yaml", "--", "touch", "/projects/blah.js").ShouldFail().Err()
Expect(err).To(ContainSubstring("unknown flag: --devfile"))
})
// TODO(feloy): Uncomment when https://github.com/openshift/odo/issues/5012 is fixed
// By("exec from a context with no component", func() {
// err := helper.Cmd("odo", "exec", "--context", "/tmp", "--", "touch", "/projects/blah.js").ShouldFail().Err()
// Expect(err).To(ContainSubstring("the current directory does not contain an odo component"))
// })
})
It("should error out when a invalid command is given by the user", func() {
utils.ExecWithInvalidCommand(commonVar.Context, cmpName, "kube")
When("odo push is executed", func() {
BeforeEach(func() {
helper.Cmd("odo", "push", "--context", commonVar.Context).ShouldPass()
})
It("should execute the given command successfully in the container", func() {
helper.Cmd("odo", "exec", "--context", commonVar.Context, "--", "touch", "/projects/blah.js").ShouldPass()
podName := commonVar.CliRunner.GetRunningPodNameByComponent(cmpName, commonVar.Project)
listDir := commonVar.CliRunner.ExecListDir(podName, commonVar.Project, "/projects")
Expect(listDir).To(ContainSubstring("blah.js"))
})
It("should error out when no command is given by the user", func() {
output := helper.Cmd("odo", "exec", "--context", commonVar.Context, "--").ShouldFail().Err()
Expect(output).To(ContainSubstring("no command was given"))
})
It("should error out when an invalid command is given by the user", func() {
output := helper.Cmd("odo", "exec", "--context", commonVar.Context, "--", "invalidCommand").ShouldFail().Out()
Expect(output).To(ContainSubstring("executable file not found in $PATH"))
})
})
It("should error out when a component is not present or when a devfile flag is used", func() {
utils.ExecCommandWithoutComponentAndDevfileFlag(commonVar.Context, cmpName)
})
})
})

View File

@@ -19,272 +19,6 @@ import (
. "github.com/onsi/gomega"
)
func useProjectIfAvailable(args []string, project string) []string {
if project != "" {
args = append(args, "--project", project)
}
return args
}
// ExecDefaultDevfileCommands executes the default devfile commands
func ExecDefaultDevfileCommands(projectDirPath, cmpName, namespace string) {
args := []string{"create", "java-springboot", cmpName}
args = useProjectIfAvailable(args, namespace)
helper.Cmd("odo", args...).ShouldPass()
helper.CopyExample(filepath.Join("source", "devfiles", "springboot", "project"), projectDirPath)
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "springboot", "devfile.yaml"), filepath.Join(projectDirPath, "devfile.yaml"))
args = []string{"push"}
args = useProjectIfAvailable(args, namespace)
output := helper.Cmd("odo", args...).ShouldPass().Out()
helper.MatchAllInOutput(output, []string{
"Executing defaultbuild command",
"mvn clean",
"Executing defaultrun command",
"spring-boot:run",
})
}
// ExecWithMissingBuildCommand executes odo push with a missing build command
func ExecWithMissingBuildCommand(projectDirPath, cmpName, namespace string) {
args := []string{"create", "nodejs", cmpName}
args = useProjectIfAvailable(args, namespace)
helper.Cmd("odo", args...).ShouldPass()
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), projectDirPath)
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile-without-devbuild.yaml"), filepath.Join(projectDirPath, "devfile.yaml"))
args = []string{"push"}
args = useProjectIfAvailable(args, namespace)
output := helper.Cmd("odo", args...).ShouldPass().Out()
Expect(output).NotTo(ContainSubstring("Executing devbuild command"))
Expect(output).To(ContainSubstring("Executing devrun command \"npm install && npm start\""))
}
// ExecWithMissingRunCommand executes odo push with a missing run command
func ExecWithMissingRunCommand(projectDirPath, cmpName, namespace string) {
args := []string{"create", "nodejs", cmpName}
args = useProjectIfAvailable(args, namespace)
helper.Cmd("odo", args...).ShouldPass()
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), projectDirPath)
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile.yaml"), filepath.Join(projectDirPath, "devfile.yaml"))
// Remove the run commands
helper.ReplaceString(filepath.Join(projectDirPath, "devfile.yaml"), "kind: run", "kind: debug")
args = []string{"push"}
args = useProjectIfAvailable(args, namespace)
output := helper.Cmd("odo", args...).ShouldFail().Err()
Expect(output).NotTo(ContainSubstring("Executing devrun command"))
Expect(output).To(ContainSubstring("the command group of kind \"run\" is not found in the devfile"))
}
// ExecWithCustomCommand executes odo push with a custom command
func ExecWithCustomCommand(projectDirPath, cmpName, namespace string) {
}
// ExecWithWrongCustomCommand executes odo push with a wrong custom command
func ExecWithWrongCustomCommand(projectDirPath, cmpName, namespace string) {
}
// ExecWithMultipleOrNoDefaults executes odo push with multiple or no default commands
func ExecWithMultipleOrNoDefaults(projectDirPath, cmpName, namespace string) {
args := []string{"create", "nodejs", cmpName}
args = useProjectIfAvailable(args, namespace)
helper.Cmd("odo", args...).ShouldPass()
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), projectDirPath)
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile-with-multiple-defaults.yaml"), filepath.Join(projectDirPath, "devfile.yaml"))
args = []string{"push"}
args = useProjectIfAvailable(args, namespace)
output := helper.Cmd("odo", args...).ShouldFail().Err()
helper.MatchAllInOutput(output, []string{
"group test error",
"currently there is more than one default command",
})
helper.DeleteFile(filepath.Join(projectDirPath, "devfile.yaml"))
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), projectDirPath)
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile-with-no-default.yaml"), filepath.Join(projectDirPath, "devfile.yaml"))
args = []string{"push"}
args = useProjectIfAvailable(args, namespace)
output = helper.Cmd("odo", args...).ShouldFail().Err()
helper.MatchAllInOutput(output, []string{
"group run error",
"currently there is no default command",
})
}
// ExecCommandWithoutGroupUsingFlags executes odo push with no command group using flags
func ExecCommandWithoutGroupUsingFlags(projectDirPath, cmpName, namespace string) {
}
// ExecWithInvalidCommandGroup executes odo push with an invalid command group
func ExecWithInvalidCommandGroup(projectDirPath, cmpName, namespace string) {
args := []string{"create", "java-springboot", cmpName}
args = useProjectIfAvailable(args, namespace)
helper.Cmd("odo", args...).ShouldPass()
helper.CopyExample(filepath.Join("source", "devfiles", "springboot", "project"), projectDirPath)
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "springboot", "devfile.yaml"), filepath.Join(projectDirPath, "devfile.yaml"))
// Remove the run commands
helper.ReplaceString(filepath.Join(projectDirPath, "devfile.yaml"), "kind: build", "kind: init")
args = []string{"push"}
args = useProjectIfAvailable(args, namespace)
output := helper.Cmd("odo", args...).ShouldFail().Err()
Expect(output).To(ContainSubstring("must be one of the following: \"build\", \"run\", \"test\", \"debug\""))
}
func ExecPushToTestParent(projectDirPath, cmpName, namespace string) {
args := []string{"create", "nodejs", cmpName}
args = useProjectIfAvailable(args, namespace)
helper.Cmd("odo", args...).ShouldPass()
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), projectDirPath)
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile-with-parent.yaml"), filepath.Join(projectDirPath, "devfile.yaml"))
args = []string{"push"}
args = useProjectIfAvailable(args, namespace)
helper.Cmd("odo", args...).ShouldPass()
args = append(args, "--build-command", "devbuild", "-f")
output := helper.Cmd("odo", args...).ShouldPass().Out()
helper.MatchAllInOutput(output, []string{"Executing devbuild command", "touch blah.js"})
}
func ExecPushWithParentOverride(projectDirPath, cmpName, appName, namespace string, freePort int) {
args := []string{"create", "nodejs", cmpName, "--app", appName}
args = useProjectIfAvailable(args, namespace)
helper.Cmd("odo", args...).ShouldPass()
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), projectDirPath)
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "parentSupport", "devfile-with-parent.yaml"), filepath.Join(projectDirPath, "devfile.yaml"))
// update the devfile with the free port
helper.ReplaceString(filepath.Join(projectDirPath, "devfile.yaml"), "(-1)", strconv.Itoa(freePort))
args = []string{"push"}
args = useProjectIfAvailable(args, namespace)
helper.Cmd("odo", args...).ShouldPass()
}
func ExecPushWithCompositeOverride(projectDirPath, cmpName, namespace string, freePort int) {
args := []string{"create", "nodejs", cmpName}
args = useProjectIfAvailable(args, namespace)
helper.Cmd("odo", args...).ShouldPass()
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), projectDirPath)
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "parentSupport", "devfile-with-parent-composite.yaml"), filepath.Join(projectDirPath, "devfile.yaml"))
// update the devfile with the free port
helper.ReplaceString(filepath.Join(projectDirPath, "devfile.yaml"), "(-1)", strconv.Itoa(freePort))
args = []string{"push"}
args = useProjectIfAvailable(args, namespace)
output := helper.Cmd("odo", args...).ShouldPass().Out()
helper.MatchAllInOutput(output, []string{"Executing createfile command", "touch /projects/testfile"})
}
func ExecPushWithMultiLayerParent(projectDirPath, cmpName, appName, namespace string, freePort int) {
args := []string{"create", "nodejs", cmpName, "--app", appName}
args = useProjectIfAvailable(args, namespace)
helper.Cmd("odo", args...).ShouldPass()
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), projectDirPath)
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "parentSupport", "devfile-with-multi-layer-parent.yaml"), filepath.Join(projectDirPath, "devfile.yaml"))
// update the devfile with the free port
helper.ReplaceString(filepath.Join(projectDirPath, "devfile.yaml"), "(-1)", strconv.Itoa(freePort))
args = []string{"push"}
args = useProjectIfAvailable(args, namespace)
helper.Cmd("odo", args...).ShouldPass()
args = []string{"push", "--build-command", "devbuild", "-f"}
args = useProjectIfAvailable(args, namespace)
helper.Cmd("odo", args...).ShouldPass()
args = []string{"push", "--build-command", "build", "-f"}
args = useProjectIfAvailable(args, namespace)
helper.Cmd("odo", args...).ShouldPass()
}
// ExecPushToTestFileChanges executes odo push with and without a file change
func ExecPushToTestFileChanges(projectDirPath, cmpName, namespace string) {
args := []string{"create", "nodejs", cmpName}
args = useProjectIfAvailable(args, namespace)
helper.Cmd("odo", args...).ShouldPass()
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), projectDirPath)
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile.yaml"), filepath.Join(projectDirPath, "devfile.yaml"))
args = []string{"push"}
args = useProjectIfAvailable(args, namespace)
helper.Cmd("odo", args...).ShouldPass()
output := helper.Cmd("odo", args...).ShouldPass().Out()
Expect(output).To(ContainSubstring("No file changes detected, skipping build"))
helper.ReplaceString(filepath.Join(projectDirPath, "server.js"), "Hello from Node.js", "UPDATED!")
output = helper.Cmd("odo", args...).ShouldPass().Out()
Expect(output).To(ContainSubstring("Syncing files to the component"))
}
// ExecPushWithForceFlag executes odo push with a force flag
func ExecPushWithForceFlag(projectDirPath, cmpName, namespace string) {
args := []string{"create", "nodejs", cmpName}
args = useProjectIfAvailable(args, namespace)
helper.Cmd("odo", args...).ShouldPass()
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), projectDirPath)
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile.yaml"), filepath.Join(projectDirPath, "devfile.yaml"))
args = []string{"push"}
args = useProjectIfAvailable(args, namespace)
helper.Cmd("odo", args...).ShouldPass()
// use the force build flag and push
args = []string{"push", "-f"}
args = useProjectIfAvailable(args, namespace)
output := helper.Cmd("odo", args...).ShouldPass().Out()
Expect(output).To(Not(ContainSubstring("No file changes detected, skipping build")))
}
// ExecPushWithNewFileAndDir executes odo push after creating a new file and dir
func ExecPushWithNewFileAndDir(projectDirPath, cmpName, namespace, newFilePath, newDirPath string) {
args := []string{"create", "nodejs", cmpName}
args = useProjectIfAvailable(args, namespace)
helper.Cmd("odo", args...).ShouldPass()
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), projectDirPath)
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile.yaml"), filepath.Join(projectDirPath, "devfile.yaml"))
// Create a new file that we plan on deleting later...
if err := helper.CreateFileWithContent(newFilePath, "hello world"); err != nil {
fmt.Printf("the foobar.txt file was not created, reason %v", err.Error())
}
// Create a new directory
helper.MakeDir(newDirPath)
// Push
args = []string{"push"}
args = useProjectIfAvailable(args, namespace)
helper.Cmd("odo", args...).ShouldPass()
}
// ExecWithHotReload executes odo push with hot reload true
func ExecWithHotReload(projectDirPath, cmpName, namespace string, hotReload bool) {
}
type OdoV1Watch struct {
SrcType string
RouteURL string
@@ -552,76 +286,6 @@ func validateContainerExecListDir(odoV1Watch OdoV1Watch, odoV2Watch OdoV2Watch,
return nil
}
// ExecCommand executes odo exec with a command
func ExecCommand(context, cmpName string) {
args := []string{"create", "nodejs", cmpName, "--context", context}
helper.Cmd("odo", args...).ShouldPass()
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), context)
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile.yaml"), filepath.Join(context, "devfile.yaml"))
args = []string{"push", "--context", context}
helper.Cmd("odo", args...).ShouldPass()
args = []string{"exec", "--context", context}
args = append(args, []string{"--", "touch", "/projects/blah.js"}...)
helper.Cmd("odo", args...).ShouldPass()
}
// ExecCommandWithoutComponentAndDevfileFlag executes odo exec without a component and with a devfile flag
func ExecCommandWithoutComponentAndDevfileFlag(context, cmpName string) {
args := []string{"create", "nodejs", cmpName, "--context", context}
helper.Cmd("odo", args...).ShouldPass()
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), context)
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile.yaml"), filepath.Join(context, "devfile.yaml"))
args = []string{"exec", "--context", context}
args = append(args, []string{"--", "touch", "/projects/blah.js"}...)
helper.Cmd("odo", args...).ShouldFail()
args = []string{"exec", "--context", context, "--devfile", "invalid.yaml"}
args = append(args, []string{"--", "touch", "/projects/blah.js"}...)
helper.Cmd("odo", args...).ShouldFail()
}
//ExecWithoutCommand executes odo exec with no user command and fails
func ExecWithoutCommand(context, cmpName string) {
args := []string{"create", "nodejs", cmpName, "--context", context}
helper.Cmd("odo", args...).ShouldPass()
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), context)
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile.yaml"), filepath.Join(context, "devfile.yaml"))
args = []string{"push", "--context", context}
helper.Cmd("odo", args...).ShouldPass()
args = []string{"exec", "--context", context}
args = append(args, "--")
output := helper.Cmd("odo", args...).ShouldFail().Err()
Expect(output).To(ContainSubstring("no command was given"))
}
//ExecWithInvalidCommand executes odo exec with a invalid command
func ExecWithInvalidCommand(context, cmpName, pushTarget string) {
args := []string{"create", "nodejs", cmpName, "--context", context}
helper.Cmd("odo", args...).ShouldPass()
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), context)
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile.yaml"), filepath.Join(context, "devfile.yaml"))
args = []string{"push", "--context", context}
helper.Cmd("odo", args...).ShouldPass()
args = []string{"exec", "--context", context}
args = append(args, "--", "invalidCommand")
output := helper.Cmd("odo", args...).ShouldFail().Err()
Expect(output).To(ContainSubstring("executable file not found in $PATH"))
}
// DeleteLocalConfig helps user to delete local config files with flags
func DeleteLocalConfig(args ...string) {
helper.Cmd("odo", args...).ShouldFail()