diff --git a/tests/integration/component.go b/tests/integration/component.go index a8fc429c23d..b81abdee095 100644 --- a/tests/integration/component.go +++ b/tests/integration/component.go @@ -18,11 +18,16 @@ import ( func componentTests(args ...string) { var oc helper.OcRunner var commonVar helper.CommonVar + var appName string + var cmpName string + cmpNameDefault := "nodejs" // This is run before every Spec (It) var _ = BeforeEach(func() { oc = helper.NewOcRunner("oc") commonVar = helper.CommonBeforeEach() + appName = "app-" + helper.RandString(5) + cmpName = "cmp-" + helper.RandString(5) }) // Clean up after the test @@ -31,185 +36,110 @@ func componentTests(args ...string) { helper.CommonAfterEach(commonVar) }) - Context("Generic machine readable output tests", func() { - - It("Command should fail if json is non-existent for a command", func() { - output := helper.Cmd("odo", "version", "-o", "json").ShouldFail().Err() - Expect(output).To(ContainSubstring("Machine readable output is not yet implemented for this command")) - }) + It("should fail if json is non-existent for a command", func() { + output := helper.Cmd("odo", "version", "-o", "json").ShouldFail().Err() + Expect(output).To(ContainSubstring("Machine readable output is not yet implemented for this command")) + }) - It("Help for odo version should not contain machine output", func() { - output := helper.Cmd("odo", "version", "--help").ShouldPass().Out() - Expect(output).NotTo(ContainSubstring("Specify output format, supported format: json")) - }) + It("should not have machine output for odo version", func() { + output := helper.Cmd("odo", "version", "--help").ShouldPass().Out() + Expect(output).NotTo(ContainSubstring("Specify output format, supported format: json")) + }) + XIt("should be able to create a git component and update it from local to git", func() { + helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context) + helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", cmpName, "--project", commonVar.Project, "--context", commonVar.Context, "--app", appName)...).ShouldPass() + helper.Cmd("odo", append(args, "push", "--context", commonVar.Context)...).ShouldPass() + + helper.Cmd("odo", "update", "--git", "https://github.com/openshift/nodejs-ex.git", "--context", commonVar.Context).ShouldPass() + // check the source location and type in the deployment config + getSourceLocation := oc.SourceLocationDC(cmpName, appName, commonVar.Project) + Expect(getSourceLocation).To(ContainSubstring("https://github.com/openshift/nodejs-ex")) + getSourceType := oc.SourceTypeDC(cmpName, appName, commonVar.Project) + Expect(getSourceType).To(ContainSubstring("git")) }) - Context("Creating component", func() { - JustBeforeEach(func() { - helper.Chdir(commonVar.Context) - }) + XIt("should be able to update a component from git to local", func() { + helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", cmpName, "--project", commonVar.Project, "--git", "https://github.com/openshift/nodejs-ex", "--context", commonVar.Context, "--app", appName)...).ShouldPass() + helper.Cmd("odo", append(args, "push", "--context", commonVar.Context)...).ShouldPass() - It("should create but not list component even in new project with --project and --context at the same time", func() { - helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context) - helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", "cmp-git", "--project", commonVar.Project, "--context", commonVar.Context, "--app", "testing")...).ShouldPass() + // update the component config according to the git component + helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context) - info := helper.LocalEnvInfo(commonVar.Context) - Expect(info.GetApplication(), "testing") - Expect(info.GetName(), "cmp-git") - helper.Cmd("odo", append(args, "push", "--context", commonVar.Context, "-v4")...).ShouldPass() - projectList := helper.Cmd("odo", "project", "list").ShouldPass().Out() - Expect(projectList).To(ContainSubstring(commonVar.Project)) - helper.Cmd("odo", "list", "--project", commonVar.Project, "--context", commonVar.Context).ShouldFail() - }) + helper.Cmd("odo", "update", "--local", "./", "--context", commonVar.Context).ShouldPass() - // works - It("should create default named component when passed same context differently", func() { - dir := filepath.Base(commonVar.Context) - helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context) - helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", "--project", commonVar.Project, "--context", ".", "--app", "testing")...).ShouldPass() - componentName := helper.GetLocalEnvInfoValueWithContext("Name", commonVar.Context) - Expect(componentName).To(ContainSubstring("nodejs")) - Expect(componentName).To(ContainSubstring(dir)) + // check the source location and type in the deployment config + getSourceLocation := oc.SourceLocationDC(cmpName, appName, commonVar.Project) + Expect(getSourceLocation).To(ContainSubstring("")) + getSourceType := oc.SourceTypeDC(cmpName, appName, commonVar.Project) + Expect(getSourceType).To(ContainSubstring("local")) + }) - info := helper.LocalEnvInfo(commonVar.Context) - Expect(info.GetApplication(), "testing") - Expect(info.GetName(), componentName) + XIt("should pass outside a odo directory with component name as parameter", func() { + helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context) + helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", cmpNameDefault, "--app", appName, "--project", commonVar.Project, "--context", commonVar.Context)...).ShouldPass() + info := helper.LocalEnvInfo(commonVar.Context) + Expect(info.GetApplication(), appName) + Expect(info.GetName(), cmpNameDefault) + helper.Cmd("odo", append(args, "push", "--context", commonVar.Context)...).ShouldPass() - helper.DeleteDir(filepath.Join(commonVar.Context, ".odo")) - helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", "--project", commonVar.Project, "--context", commonVar.Context, "--app", "testing")...).ShouldPass() - newComponentName := helper.GetLocalEnvInfoValueWithContext("Name", commonVar.Context) - Expect(newComponentName).To(ContainSubstring("nodejs")) - Expect(newComponentName).To(ContainSubstring(dir)) - }) + cmpListOutput := helper.Cmd("odo", append(args, "list", "--app", appName, "--project", commonVar.Project)...).ShouldPass() + Expect(cmpListOutput).To(ContainSubstring(cmpNameDefault)) - It("should show an error when ref flag is provided with sources except git", func() { - outputErr := helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", "--project", commonVar.Project, "cmp-git", "--ref", "test")...).ShouldFail().Err() - Expect(outputErr).To(ContainSubstring("the --ref flag is only valid for --git flag")) - }) + actualDesCompJSON := helper.Cmd("odo", append(args, "describe", cmpNameDefault, "--app", appName, "--project", commonVar.Project, "-o", "json")...).ShouldPass().Out() + valuesDescCJ := gjson.GetMany(actualDesCompJSON, "kind", "metadata.name", "spec.app", "spec.type", "status.state") + expectedDescCJ := []string{"Component", "nodejs", "app", "nodejs", "Pushed"} + Expect(helper.GjsonMatcher(valuesDescCJ, expectedDescCJ)).To(Equal(true)) - It("create component twice fails from same directory", func() { - helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", "nodejs", "--project", commonVar.Project)...).ShouldPass() - output := helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", "nodejs", "--project", commonVar.Project)...).ShouldFail().Err() - Expect(output).To(ContainSubstring("this directory already contains a component")) - }) + helper.Cmd("odo", append(args, "delete", cmpNameDefault, "--app", appName, "--project", commonVar.Project, "-f")...).ShouldPass() + }) - // TODO: Fix later - // It("should list out pushed components of different projects in json format along with path flag", func() { - // helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context) - // helper.CmdShouldPass("odo", append(args, "create", "--s2i", "nodejs", "nodejs", "--project", commonVar.Project)...) - // info := helper.LocalEnvInfo(commonVar.Context) - // Expect(info.GetApplication(), "app") - // Expect(info.GetName(), "nodejs") - // helper.CmdShouldPass("odo", append(args, "push")...) - - // project2 := helper.CreateRandProject() - // context2 := helper.CreateNewContext() - // helper.Chdir(context2) - // helper.CopyExample(filepath.Join("source", "python"), context2) - // helper.CmdShouldPass("odo", append(args, "create", "--s2i", "python", "python", "--project", project2)...) - // info = helper.LocalEnvInfo(context2) - // Expect(info.GetApplication(), "app") - // Expect(info.GetName(), "python") - - // helper.CmdShouldPass("odo", append(args, "push")...) - - // actual, err := helper.Unindented(helper.CmdShouldPass("odo", append(args, "list", "-o", "json", "--path", filepath.Dir(commonVar.Context))...)) - // Expect(err).Should(BeNil()) - // helper.Chdir(commonVar.Context) - // helper.DeleteDir(context2) - // helper.DeleteProject(project2) - // // this orders the json - // expected := fmt.Sprintf(`"metadata":{"name":"nodejs","namespace":"%s","creationTimestamp":null},"spec":{"app":"app","type":"nodejs","sourceType": "local","ports":["8080/TCP"]}`, commonVar.Project) - // Expect(actual).Should(ContainSubstring(expected)) - // // this orders the json - // expected = fmt.Sprintf(`"metadata":{"name":"python","namespace":"%s","creationTimestamp":null},"spec":{"app":"app","type":"python","sourceType": "local","ports":["8080/TCP"]}`, project2) - // Expect(actual).Should(ContainSubstring(expected)) - - // }) - - It("should list the component", func() { - helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context) - helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", "cmp-git", "--project", commonVar.Project, "--context", commonVar.Context, "--app", "testing")...).ShouldPass() - info := helper.LocalEnvInfo(commonVar.Context) - Expect(info.GetApplication(), "testing") - Expect(info.GetName(), "cmp-git") - helper.Cmd("odo", append(args, "push", "--context", commonVar.Context)...).ShouldPass() + It("should retain the same environment variable on multiple push", func() { + helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context) + helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", cmpName, "--app", appName, "--project", commonVar.Project, "--context", commonVar.Context)...).ShouldPass() + helper.Cmd("odo", append(args, "push", "--context", commonVar.Context)...).ShouldPass() + + helper.Chdir(commonVar.Context) + helper.Cmd("odo", "config", "set", "--env", "FOO=BAR").ShouldPass() + helper.Cmd("odo", append(args, "push")...).ShouldPass() + info := helper.LocalEnvInfo(commonVar.Context) + Expect(info.GetApplication(), appName) + Expect(info.GetName(), cmpName) + envVars := oc.GetEnvsDevFileDeployment(cmpName, appName, commonVar.Project) + val, ok := envVars["FOO"] + Expect(ok).To(BeTrue()) + Expect(val).To(Equal("BAR")) + }) - cmpList := helper.Cmd("odo", append(args, "list", "--project", commonVar.Project)...).ShouldPass().Out() - Expect(cmpList).To(ContainSubstring("cmp-git")) - actualCompListJSON := helper.Cmd("odo", append(args, "list", "--project", commonVar.Project, "-o", "json")...).ShouldPass().Out() - valuesCList := gjson.GetMany(actualCompListJSON, "kind", "devfileComponents.0.kind", "devfileComponents.0.metadata.name", "devfileComponents.0.spec.app") - expectedCList := []string{"List", "Component", "cmp-git", "testing"} - Expect(helper.GjsonMatcher(valuesCList, expectedCList)).To(Equal(true)) + When("in context directory", func() { - cmpAllList := helper.Cmd("odo", append(args, "list", "--all-apps")...).ShouldPass().Out() - Expect(cmpAllList).To(ContainSubstring("cmp-git")) - helper.Cmd("odo", append(args, "delete", "cmp-git", "-f")...).ShouldPass() + BeforeEach(func() { + helper.Chdir(commonVar.Context) }) - It("should list the component when it is not pushed", func() { - helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context) - helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", "cmp-git", "--project", commonVar.Project, "--context", commonVar.Context, "--app", "testing")...).ShouldPass() - - info := helper.LocalEnvInfo(commonVar.Context) - Expect(info.GetApplication(), "testing") - Expect(info.GetName(), "cmp-git") - cmpList := helper.Cmd("odo", append(args, "list", "--context", commonVar.Context)...).ShouldPass().Out() - helper.MatchAllInOutput(cmpList, []string{"cmp-git", "Not Pushed"}) - helper.Cmd("odo", append(args, "delete", "-f", "--all", "--context", commonVar.Context)...).ShouldPass() + It("should show an error when ref flag is provided with sources except git", func() { + outputErr := helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", "--project", commonVar.Project, cmpName, "--ref", "test")...).ShouldFail().Err() + Expect(outputErr).To(ContainSubstring("the --ref flag is only valid for --git flag")) }) - // It("should list the state as unknown for disconnected cluster", func() { - // helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context) - // helper.CmdShouldPass("odo", append(args, "create", "--s2i", "nodejs", "cmp-git", "--project", commonVar.Project, "--context", commonVar.Context, "--app", "testing")...) - // info := helper.LocalEnvInfo(commonVar.Context) - // Expect(info.GetApplication(), "testing") - // Expect(info.GetName(), "cmp-git") - // kubeconfigOrig := os.Getenv("KUBECONFIG") - - // unset := func() { - // // KUBECONFIG defaults to ~/.kube/config so it can be empty in some cases. - // if kubeconfigOrig != "" { - // os.Setenv("KUBECONFIG", kubeconfigOrig) - // } else { - // os.Unsetenv("KUBECONFIG") - // } - // } - - // os.Setenv("KUBECONFIG", "/no/such/path") - - // defer unset() - // cmpList := helper.CmdShouldPass("odo", append(args, "list", "--context", commonVar.Context, "--v", "9")...) - - // helper.MatchAllInOutput(cmpList, []string{"cmp-git", "Unknown"}) - // unset() + It("should succeed listing catalog components", func() { + // Since components catalog is constantly changing, we simply check to see if this command passes.. rather than checking the JSON each time. + helper.Cmd("odo", "catalog", "list", "components", "-o", "json").ShouldPass() + }) - // fmt.Printf("kubeconfig before delete %v", os.Getenv("KUBECONFIG")) - // helper.CmdShouldPass("odo", append(args, "delete", "-f", "--all", "--context", commonVar.Context)...) - // }) + It("should fail the create command as --git flag, which is specific to s2i component creation, is used without --s2i flag", func() { + output := helper.Cmd("odo", "create", "nodejs", cmpName, "--git", "https://github.com/openshift/nodejs-ex", "--context", commonVar.Context, "--app", appName).ShouldFail().Err() + Expect(output).Should(ContainSubstring("flag --git, requires --s2i flag to be set, when deploying S2I (Source-to-Image) components")) + }) - It("should describe the component when it is not pushed", func() { - helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context) - helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", "cmp-git", "--project", commonVar.Project, "--context", commonVar.Context, "--app", "testing")...).ShouldPass() - helper.Cmd("odo", "url", "create", "url-1", "--context", commonVar.Context).ShouldPass() - helper.Cmd("odo", "url", "create", "url-2", "--context", commonVar.Context).ShouldPass() - helper.Cmd("odo", "storage", "create", "storage-1", "--size", "1Gi", "--path", "/data1", "--context", commonVar.Context).ShouldPass() - info := helper.LocalEnvInfo(commonVar.Context) - Expect(info.GetApplication(), "testing") - Expect(info.GetName(), "cmp-git") - cmpDescribe := helper.Cmd("odo", append(args, "describe", "--context", commonVar.Context)...).ShouldPass().Out() - helper.MatchAllInOutput(cmpDescribe, []string{ - "cmp-git", - "nodejs", - "url-1", - "url-2", - "storage-1", - }) + It("should fail the create command as --binary flag, which is specific to s2i component creation, is used without --s2i flag", func() { + helper.CopyExample(filepath.Join("binary", "java", "openjdk"), commonVar.Context) + output := helper.Cmd("odo", "create", "java:8", "sb-jar-test", "--binary", filepath.Join(commonVar.Context, "sb.jar"), "--context", commonVar.Context).ShouldFail().Err() + Expect(output).Should(ContainSubstring("flag --binary, requires --s2i flag to be set, when deploying S2I (Source-to-Image) components")) }) - It("checks that odo describe works for s2i component from a devfile directory", func() { + It("should work for s2i component from a devfile directory", func() { newContext := path.Join(commonVar.Context, "newContext") helper.MakeDir(newContext) helper.Chdir(newContext) @@ -226,215 +156,289 @@ func componentTests(args ...string) { It("should list the component in the same app when one is pushed and the other one is not pushed", func() { helper.Chdir(commonVar.OriginalWorkingDirectory) helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context) - helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", "cmp-git", "--project", commonVar.Project, "--context", commonVar.Context, "--app", "testing")...).ShouldPass() + helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", cmpName, "--project", commonVar.Project, "--context", commonVar.Context, "--app", appName)...).ShouldPass() info := helper.LocalEnvInfo(commonVar.Context) - Expect(info.GetApplication(), "testing") - Expect(info.GetName(), "cmp-git") + Expect(info.GetApplication(), appName) + Expect(info.GetName(), cmpName) helper.Cmd("odo", append(args, "push", "--context", commonVar.Context)...).ShouldPass() context2 := helper.CreateNewContext() helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context) - helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", "cmp-git-2", "--project", commonVar.Project, "--context", context2, "--app", "testing")...).ShouldPass() + helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", "cmp-git-2", "--project", commonVar.Project, "--context", context2, "--app", appName)...).ShouldPass() info = helper.LocalEnvInfo(context2) - Expect(info.GetApplication(), "testing") + Expect(info.GetApplication(), appName) Expect(info.GetName(), "cmp-git-2") cmpList := helper.Cmd("odo", append(args, "list", "--context", context2)...).ShouldPass().Out() - helper.MatchAllInOutput(cmpList, []string{"cmp-git", "cmp-git-2", "Not Pushed", "Pushed"}) + helper.MatchAllInOutput(cmpList, []string{cmpName, "cmp-git-2", "Not Pushed", "Pushed"}) helper.Cmd("odo", append(args, "delete", "-f", "--all", "--context", commonVar.Context)...).ShouldPass() helper.Cmd("odo", append(args, "delete", "-f", "--all", "--context", context2)...).ShouldPass() helper.DeleteDir(context2) }) - It("should succeed listing catalog components", func() { - // Since components catalog is constantly changing, we simply check to see if this command passes.. rather than checking the JSON each time. - helper.Cmd("odo", "catalog", "list", "components", "-o", "json").ShouldPass() - }) - - It("binary component should not fail when --context is not set", func() { - oc.ImportJavaIS(commonVar.Project) - helper.CopyExample(filepath.Join("binary", "java", "openjdk"), commonVar.Context) - // Was failing due to https://github.com/openshift/odo/issues/1969 - helper.Cmd("odo", append(args, "create", "--s2i", "java:8", "sb-jar-test", "--project", - commonVar.Project, "--binary", filepath.Join(commonVar.Context, "sb.jar"))...).ShouldPass() - info := helper.LocalEnvInfo(commonVar.Context) - Expect(info.GetName(), "sb-jar-test") - }) - - It("binary component should fail when --binary is not in --context folder", func() { - oc.ImportJavaIS(commonVar.Project) - helper.CopyExample(filepath.Join("binary", "java", "openjdk"), commonVar.Context) - - newContext := helper.CreateNewContext() - defer helper.DeleteDir(newContext) - - output := helper.Cmd("odo", append(args, "create", "--s2i", "java:8", "sb-jar-test", "--project", - commonVar.Project, "--binary", filepath.Join(commonVar.Context, "sb.jar"), "--context", newContext)...).ShouldFail().Err() - Expect(output).To(ContainSubstring("inside of the context directory")) - }) - - It("binary component is valid if path is relative and includes ../", func() { - oc.ImportJavaIS(commonVar.Project) - helper.CopyExample(filepath.Join("binary", "java", "openjdk"), commonVar.Context) - - relativeContext := fmt.Sprintf("..%c%s", filepath.Separator, filepath.Base(commonVar.Context)) - fmt.Printf("relativeContext = %#v\n", relativeContext) - - if runtime.GOOS == "darwin" { - helper.Cmd("odo", append(args, "create", "--s2i", "java:8", "sb-jar-test", "--project", - commonVar.Project, "--binary", filepath.Join("/private", commonVar.Context, "sb.jar"), "--context", relativeContext)...).ShouldPass() - } else { - helper.Cmd("odo", append(args, "create", "--s2i", "java:8", "sb-jar-test", "--project", - commonVar.Project, "--binary", filepath.Join(commonVar.Context, "sb.jar"), "--context", relativeContext)...).ShouldPass() - } - info := helper.LocalEnvInfo(relativeContext) - Expect(info.GetApplication(), "app") - Expect(info.GetName(), "sb-jar-test") - }) - - It("should fail the create command as --git flag, which is specific to s2i component creation, is used without --s2i flag", func() { - output := helper.Cmd("odo", "create", "nodejs", "cmp-git", "--git", "https://github.com/openshift/nodejs-ex", "--context", commonVar.Context, "--app", "testing").ShouldFail().Err() - Expect(output).Should(ContainSubstring("flag --git, requires --s2i flag to be set, when deploying S2I (Source-to-Image) components")) - }) - - It("should fail the create command as --binary flag, which is specific to s2i component creation, is used without --s2i flag", func() { - helper.CopyExample(filepath.Join("binary", "java", "openjdk"), commonVar.Context) - - output := helper.Cmd("odo", "create", "java:8", "sb-jar-test", "--binary", filepath.Join(commonVar.Context, "sb.jar"), "--context", commonVar.Context).ShouldFail().Err() - Expect(output).Should(ContainSubstring("flag --binary, requires --s2i flag to be set, when deploying S2I (Source-to-Image) components")) - }) - }) - - Context("when component is in the current directory and --project flag is used", func() { - - appName := "app" - componentName := "my-component" - - JustBeforeEach(func() { - helper.Chdir(commonVar.Context) - }) - - It("create local nodejs component twice and fail", func() { - helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context) - helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", "--project", commonVar.Project, "--env", "key=value,key1=value1")...).ShouldPass() - output := helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", "--project", commonVar.Project, "--env", "key=value,key1=value1")...).ShouldFail().Err() - Expect(output).To(ContainSubstring("this directory already contains a component")) - }) - - It("creates and pushes local nodejs component and then deletes --all", func() { - helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context) - helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", componentName, "--app", appName, "--project", commonVar.Project, "--env", "key=value,key1=value1")...).ShouldPass() - info := helper.LocalEnvInfo(commonVar.Context) - Expect(info.GetApplication(), appName) - Expect(info.GetName(), componentName) - helper.Cmd("odo", append(args, "push", "--context", commonVar.Context)...).ShouldPass() - helper.Cmd("odo", append(args, "delete", "--context", commonVar.Context, "-f", "--all")...).ShouldPass() - componentList := helper.Cmd("odo", append(args, "list", "--app", appName, "--project", commonVar.Project)...).ShouldPass().Out() - Expect(componentList).NotTo(ContainSubstring(componentName)) - files := helper.ListFilesInDir(commonVar.Context) - Expect(files).NotTo(ContainElement(".odo")) - }) - - It("creates a local python component, pushes it and then deletes it using --all flag", func() { + It("should create a local python component, push it and then delete it using --all flag", func() { helper.CopyExample(filepath.Join("source", "python"), commonVar.Context) - helper.Cmd("odo", append(args, "create", "--s2i", "python", componentName, "--app", appName, "--project", commonVar.Project, "--context", commonVar.Context)...).ShouldPass() + helper.Cmd("odo", append(args, "create", "--s2i", "python", cmpName, "--app", appName, "--project", commonVar.Project, "--context", commonVar.Context)...).ShouldPass() info := helper.LocalEnvInfo(commonVar.Context) Expect(info.GetApplication(), appName) - Expect(info.GetName(), componentName) + Expect(info.GetName(), cmpName) helper.Cmd("odo", append(args, "push", "--context", commonVar.Context)...).ShouldPass() helper.Cmd("odo", append(args, "delete", "--context", commonVar.Context, "-f")...).ShouldPass() helper.Cmd("odo", append(args, "delete", "--all", "-f", "--context", commonVar.Context)...).ShouldPass() componentList := helper.Cmd("odo", append(args, "list", "--app", appName, "--project", commonVar.Project)...).ShouldPass().Out() - Expect(componentList).NotTo(ContainSubstring(componentName)) + Expect(componentList).NotTo(ContainSubstring(cmpName)) files := helper.ListFilesInDir(commonVar.Context) Expect(files).NotTo(ContainElement(".odo")) }) - It("creates a local python component, pushes it and then deletes it using --all flag in local directory", func() { + It("should create a local python component, push it and then delete it using --all flag in local directory", func() { helper.CopyExample(filepath.Join("source", "python"), commonVar.Context) - helper.Cmd("odo", append(args, "create", "--s2i", "python", componentName, "--app", appName, "--project", commonVar.Project)...).ShouldPass() + helper.Cmd("odo", append(args, "create", "--s2i", "python", cmpName, "--app", appName, "--project", commonVar.Project)...).ShouldPass() info := helper.LocalEnvInfo(commonVar.Context) Expect(info.GetApplication(), appName) - Expect(info.GetName(), componentName) + Expect(info.GetName(), cmpName) helper.Cmd("odo", append(args, "push")...).ShouldPass() helper.Cmd("odo", append(args, "delete", "--all", "-f")...).ShouldPass() componentList := helper.Cmd("odo", append(args, "list", "--app", appName, "--project", commonVar.Project)...).ShouldPass().Out() - Expect(componentList).NotTo(ContainSubstring(componentName)) + Expect(componentList).NotTo(ContainSubstring(cmpName)) files := helper.ListFilesInDir(commonVar.Context) Expect(files).NotTo(ContainElement(".odo")) }) - It("creates a local python component and check for unsupported warning", func() { + It("should create a local python component and check for unsupported warning", func() { helper.CopyExample(filepath.Join("source", "python"), commonVar.Context) - output := helper.Cmd("odo", append(args, "create", "--s2i", "python", componentName, "--app", appName, "--project", commonVar.Project, "--context", commonVar.Context)...).ShouldPass().Out() + output := helper.Cmd("odo", append(args, "create", "--s2i", "python", cmpName, "--app", appName, "--project", commonVar.Project, "--context", commonVar.Context)...).ShouldPass().Out() Expect(output).To(ContainSubstring("Warning: python is not fully supported by odo, and it is not guaranteed to work")) }) - It("creates a local nodejs component and check unsupported warning hasn't occurred", func() { + It("should create a local nodejs component and check unsupported warning hasn't occurred", func() { helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context) - output := helper.Cmd("odo", append(args, "create", "--s2i", "nodejs:latest", componentName, "--app", appName, "--project", commonVar.Project, "--context", commonVar.Context)...).ShouldPass().Out() + output := helper.Cmd("odo", append(args, "create", "--s2i", "nodejs:latest", cmpName, "--app", appName, "--project", commonVar.Project, "--context", commonVar.Context)...).ShouldPass().Out() Expect(output).NotTo(ContainSubstring("Warning")) }) - It("creates a local java component and check unsupported warning hasn't occurred", func() { + It("should create a local java component and check unsupported warning hasn't occurred", func() { helper.CopyExample(filepath.Join("binary", "java", "openjdk"), commonVar.Context) - output := helper.Cmd("odo", append(args, "create", "--s2i", "java:latest", componentName, "--project", commonVar.Project, "--context", commonVar.Context)...).ShouldPass().Out() + output := helper.Cmd("odo", append(args, "create", "--s2i", "java:latest", cmpName, "--project", commonVar.Project, "--context", commonVar.Context)...).ShouldPass().Out() Expect(output).NotTo(ContainSubstring("Warning")) }) - }) - // devfile doesn't support odo update command - // Context("odo component updating", func() { + // TODO: Fix later + XIt("should list out pushed components of different projects in json format along with path flag", func() { + helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context) + helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", "nodejs", "--project", commonVar.Project)...).ShouldPass() + info := helper.LocalEnvInfo(commonVar.Context) + Expect(info.GetApplication(), "app") + Expect(info.GetName(), "nodejs") + helper.Cmd("odo", append(args, "push")...).ShouldPass() - // It("should be able to create a git component and update it from local to git", func() { - // helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context) - // helper.CmdShouldPass("odo", append(args, "create", "--s2i", "nodejs", "cmp-git", "--project", commonVar.Project, "--context", commonVar.Context, "--app", "testing")...) - // helper.CmdShouldPass("odo", append(args, "push", "--context", commonVar.Context)...) + project2 := helper.CreateRandProject() + context2 := helper.CreateNewContext() + helper.Chdir(context2) + helper.CopyExample(filepath.Join("source", "python"), context2) + helper.Cmd("odo", append(args, "create", "--s2i", "python", "python", "--project", project2)...).ShouldPass() + info = helper.LocalEnvInfo(context2) + Expect(info.GetApplication(), "app") + Expect(info.GetName(), "python") - // helper.CmdShouldPass("odo", "update", "--git", "https://github.com/openshift/nodejs-ex.git", "--context", commonVar.Context) - // // check the source location and type in the deployment config - // getSourceLocation := oc.SourceLocationDC("cmp-git", "testing", commonVar.Project) - // Expect(getSourceLocation).To(ContainSubstring("https://github.com/openshift/nodejs-ex")) - // getSourceType := oc.SourceTypeDC("cmp-git", "testing", commonVar.Project) - // Expect(getSourceType).To(ContainSubstring("git")) - // }) + helper.Cmd("odo", append(args, "push")...).ShouldPass() - // It("should be able to update a component from git to local", func() { - // helper.CmdShouldPass("odo", append(args, "create", "--s2i", "nodejs", "cmp-git", "--project", commonVar.Project, "--git", "https://github.com/openshift/nodejs-ex", "--context", commonVar.Context, "--app", "testing")...) - // helper.CmdShouldPass("odo", append(args, "push", "--context", commonVar.Context)...) + actual, err := helper.Unindented(helper.Cmd("odo", append(args, "list", "-o", "json", "--path", filepath.Dir(commonVar.Context))...).ShouldPass().Out()) + Expect(err).Should(BeNil()) + helper.Chdir(commonVar.Context) + helper.DeleteDir(context2) + helper.DeleteProject(project2) + // this orders the json + expected := fmt.Sprintf(`"metadata":{"name":"nodejs","namespace":"%s","creationTimestamp":null},"spec":{"app":"app","type":"nodejs","sourceType": "local","ports":["8080/TCP"]}`, commonVar.Project) + Expect(actual).Should(ContainSubstring(expected)) + // this orders the json + expected = fmt.Sprintf(`"metadata":{"name":"python","namespace":"%s","creationTimestamp":null},"spec":{"app":"app","type":"python","sourceType": "local","ports":["8080/TCP"]}`, project2) + Expect(actual).Should(ContainSubstring(expected)) - // // update the component config according to the git component - // helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context) + }) - // helper.CmdShouldPass("odo", "update", "--local", "./", "--context", commonVar.Context) + When("creating a named s2i nodejs component", func() { - // // check the source location and type in the deployment config - // getSourceLocation := oc.SourceLocationDC("cmp-git", "testing", commonVar.Project) - // Expect(getSourceLocation).To(ContainSubstring("")) - // getSourceType := oc.SourceTypeDC("cmp-git", "testing", commonVar.Project) - // Expect(getSourceType).To(ContainSubstring("local")) - // }) - // }) + BeforeEach(func() { + helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context) + helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", cmpName, "--project", commonVar.Project, "--context", commonVar.Context, "--app", appName)...).ShouldPass() + info := helper.LocalEnvInfo(commonVar.Context) + Expect(info.GetApplication(), appName) + Expect(info.GetName(), cmpName) + }) - Context("odo component delete, list and describe", func() { - appName := "app" - cmpName := "nodejs" + It("should list the component when it is not pushed", func() { + cmpList := helper.Cmd("odo", append(args, "list", "--context", commonVar.Context)...).ShouldPass().Out() + helper.MatchAllInOutput(cmpList, []string{cmpName, "Not Pushed"}) + helper.Cmd("odo", append(args, "delete", "-f", "--all", "--context", commonVar.Context)...).ShouldPass() + }) - It("should pass inside a odo directory without component name as parameter", func() { + XIt("should list the state as unknown for disconnected cluster", func() { + kubeconfigOrig := os.Getenv("KUBECONFIG") + + unset := func() { + // KUBECONFIG defaults to ~/.kube/config so it can be empty in some cases. + if kubeconfigOrig != "" { + os.Setenv("KUBECONFIG", kubeconfigOrig) + } else { + os.Unsetenv("KUBECONFIG") + } + } + + os.Setenv("KUBECONFIG", "/no/such/path") + + defer unset() + cmpList := helper.Cmd("odo", append(args, "list", "--context", commonVar.Context, "--v", "9")...).ShouldPass().Out() + + helper.MatchAllInOutput(cmpList, []string{cmpName, "Unknown"}) + unset() + + fmt.Printf("kubeconfig before delete %v", os.Getenv("KUBECONFIG")) + helper.Cmd("odo", append(args, "delete", "-f", "--all", "--context", commonVar.Context)...).ShouldPass() + }) + + It("should describe the component when it is not pushed", func() { + helper.Cmd("odo", "url", "create", "url-1", "--context", commonVar.Context).ShouldPass() + helper.Cmd("odo", "url", "create", "url-2", "--context", commonVar.Context).ShouldPass() + helper.Cmd("odo", "storage", "create", "storage-1", "--size", "1Gi", "--path", "/data1", "--context", commonVar.Context).ShouldPass() + cmpDescribe := helper.Cmd("odo", append(args, "describe", "--context", commonVar.Context)...).ShouldPass().Out() + helper.MatchAllInOutput(cmpDescribe, []string{ + cmpName, + "nodejs", + "url-1", + "url-2", + "storage-1", + }) + + }) + + It("should fail to create component twice from same directory", func() { + output := helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", cmpName, "--project", commonVar.Project)...).ShouldFail().Err() + Expect(output).To(ContainSubstring("this directory already contains a component")) + }) + + When("odo push is executed", func() { + + BeforeEach(func() { + helper.Cmd("odo", append(args, "push", "--context", commonVar.Context)...).ShouldPass() + }) + + It("should not list component even in new project with --project and --context at the same time", func() { + projectList := helper.Cmd("odo", "project", "list").ShouldPass().Out() + Expect(projectList).To(ContainSubstring(commonVar.Project)) + helper.Cmd("odo", "list", "--project", commonVar.Project, "--context", commonVar.Context).ShouldFail() + }) + + It("should list the component", func() { + cmpList := helper.Cmd("odo", append(args, "list", "--project", commonVar.Project)...).ShouldPass().Out() + Expect(cmpList).To(ContainSubstring(cmpName)) + actualCompListJSON := helper.Cmd("odo", append(args, "list", "--project", commonVar.Project, "-o", "json")...).ShouldPass().Out() + valuesCList := gjson.GetMany(actualCompListJSON, "kind", "devfileComponents.0.kind", "devfileComponents.0.metadata.name", "devfileComponents.0.spec.app") + expectedCList := []string{"List", "Component", cmpName, appName} + Expect(helper.GjsonMatcher(valuesCList, expectedCList)).To(Equal(true)) + + cmpAllList := helper.Cmd("odo", append(args, "list", "--all-apps")...).ShouldPass().Out() + Expect(cmpAllList).To(ContainSubstring(cmpName)) + }) + + It("should delete --all", func() { + helper.Cmd("odo", append(args, "delete", "--context", commonVar.Context, "-f", "--all")...).ShouldPass() + componentList := helper.Cmd("odo", append(args, "list", "--app", appName, "--project", commonVar.Project)...).ShouldPass().Out() + Expect(componentList).NotTo(ContainSubstring(cmpName)) + files := helper.ListFilesInDir(commonVar.Context) + Expect(files).NotTo(ContainElement(".odo")) + }) + }) + }) + + When("creating an s2i nodejs component with context .", func() { + + BeforeEach(func() { + helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context) + helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", "--project", commonVar.Project, "--context", ".", "--app", appName)...).ShouldPass() + }) + + It("should create default named component when passed same context differently", func() { + dir := filepath.Base(commonVar.Context) + componentName := helper.GetLocalEnvInfoValueWithContext("Name", commonVar.Context) + Expect(componentName).To(ContainSubstring("nodejs")) + Expect(componentName).To(ContainSubstring(dir)) + + info := helper.LocalEnvInfo(commonVar.Context) + Expect(info.GetApplication(), appName) + Expect(info.GetName(), componentName) + + helper.DeleteDir(filepath.Join(commonVar.Context, ".odo")) + helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", "--project", commonVar.Project, "--context", commonVar.Context, "--app", appName)...).ShouldPass() + newComponentName := helper.GetLocalEnvInfoValueWithContext("Name", commonVar.Context) + Expect(newComponentName).To(ContainSubstring("nodejs")) + Expect(newComponentName).To(ContainSubstring(dir)) + }) + }) + + When("a binary is copied in the current directory", func() { + + BeforeEach(func() { + oc.ImportJavaIS(commonVar.Project) + helper.CopyExample(filepath.Join("binary", "java", "openjdk"), commonVar.Context) + + }) + + It("should not fail when --context is not set", func() { + // Was failing due to https://github.com/openshift/odo/issues/1969 + helper.Cmd("odo", append(args, "create", "--s2i", "java:8", cmpName, "--project", + commonVar.Project, "--binary", filepath.Join(commonVar.Context, "sb.jar"))...).ShouldPass() + info := helper.LocalEnvInfo(commonVar.Context) + Expect(info.GetName(), cmpName) + }) + + It("should fail when --binary is not in --context folder", func() { + newContext := helper.CreateNewContext() + defer helper.DeleteDir(newContext) + + output := helper.Cmd("odo", append(args, "create", "--s2i", "java:8", cmpName, "--project", + commonVar.Project, "--binary", filepath.Join(commonVar.Context, "sb.jar"), "--context", newContext)...).ShouldFail().Err() + Expect(output).To(ContainSubstring("inside of the context directory")) + }) + + It("should be valid if path is relative and includes ../", func() { + relativeContext := fmt.Sprintf("..%c%s", filepath.Separator, filepath.Base(commonVar.Context)) + fmt.Printf("relativeContext = %#v\n", relativeContext) + + if runtime.GOOS == "darwin" { + helper.Cmd("odo", append(args, "create", "--s2i", "java:8", cmpName, "--project", + commonVar.Project, "--binary", filepath.Join("/private", commonVar.Context, "sb.jar"), "--context", relativeContext)...).ShouldPass() + } else { + helper.Cmd("odo", append(args, "create", "--s2i", "java:8", cmpName, "--project", + commonVar.Project, "--binary", filepath.Join(commonVar.Context, "sb.jar"), "--context", relativeContext)...).ShouldPass() + } + info := helper.LocalEnvInfo(relativeContext) + Expect(info.GetApplication(), "app") + Expect(info.GetName(), cmpName) + }) + }) + }) + + When("creating an s2i component", func() { + + BeforeEach(func() { helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context) - helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", cmpName, "--app", appName, "--project", commonVar.Project, "--context", commonVar.Context)...).ShouldPass() - helper.Cmd("odo", "url", "create", "example", "--context", commonVar.Context).ShouldPass() + helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", cmpNameDefault, "--app", appName, "--project", commonVar.Project, "--context", commonVar.Context)...).ShouldPass() info := helper.LocalEnvInfo(commonVar.Context) Expect(info.GetApplication(), appName) - Expect(info.GetName(), cmpName) + Expect(info.GetName(), cmpNameDefault) + }) + + It("should pass inside a odo directory without component name as parameter", func() { + helper.Cmd("odo", "url", "create", "example", "--context", commonVar.Context).ShouldPass() helper.Cmd("odo", append(args, "push", "--context", commonVar.Context)...).ShouldPass() // changing directory to the context directory helper.Chdir(commonVar.Context) cmpListOutput := helper.Cmd("odo", append(args, "list")...).ShouldPass().Out() - Expect(cmpListOutput).To(ContainSubstring(cmpName)) + Expect(cmpListOutput).To(ContainSubstring(cmpNameDefault)) cmpDescribe := helper.Cmd("odo", append(args, "describe")...).ShouldPass().Out() - helper.MatchAllInOutput(cmpDescribe, []string{cmpName, "nodejs"}) + helper.MatchAllInOutput(cmpDescribe, []string{cmpNameDefault, "nodejs"}) url := helper.DetermineRouteURL(commonVar.Context) Expect(cmpDescribe).To(ContainSubstring(url)) @@ -443,85 +447,111 @@ func componentTests(args ...string) { }) It("should fail outside a odo directory without component name as parameter", func() { - helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context) - helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", cmpName, "--app", appName, "--project", commonVar.Project, "--context", commonVar.Context)...).ShouldPass() - info := helper.LocalEnvInfo(commonVar.Context) - Expect(info.GetApplication(), appName) - Expect(info.GetName(), cmpName) helper.Cmd("odo", append(args, "push", "--context", commonVar.Context)...).ShouldPass() - // commands should fail as the component name is missing helper.Cmd("odo", append(args, "describe", "--app", appName, "--project", commonVar.Project)...).ShouldFail() helper.Cmd("odo", append(args, "delete", "-f", "--app", appName, "--project", commonVar.Project)...).ShouldFail() }) - // issue https://github.com/openshift/odo/issues/4451 - // It("should pass outside a odo directory with component name as parameter", func() { - // helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context) - // helper.CmdShouldPass("odo", append(args, "create", "--s2i", "nodejs", cmpName, "--app", appName, "--project", commonVar.Project, "--context", commonVar.Context)...) - // info := helper.LocalEnvInfo(commonVar.Context) - // Expect(info.GetApplication(), appName) - // Expect(info.GetName(), cmpName) - // helper.CmdShouldPass("odo", append(args, "push", "--context", commonVar.Context)...) + }) - // cmpListOutput := helper.CmdShouldPass("odo", append(args, "list", "--app", appName, "--project", commonVar.Project)...) - // Expect(cmpListOutput).To(ContainSubstring(cmpName)) + When("creating a named s2i component with urls and storages", func() { - // actualDesCompJSON := helper.CmdShouldPass("odo", append(args, "describe", cmpName, "--app", appName, "--project", commonVar.Project, "-o", "json")...) - // valuesDescCJ := gjson.GetMany(actualDesCompJSON, "kind", "metadata.name", "spec.app", "spec.type", "status.state") - // expectedDescCJ := []string{"Component", "nodejs", "app", "nodejs", "Pushed"} - // Expect(helper.GjsonMatcher(valuesDescCJ, expectedDescCJ)).To(Equal(true)) + BeforeEach(func() { + helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context) + helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", cmpName, "--app", appName, "--project", commonVar.Project, "--context", commonVar.Context)...).ShouldPass() + info := helper.LocalEnvInfo(commonVar.Context) + Expect(info.GetApplication(), appName) + Expect(info.GetName(), cmpName) - // helper.CmdShouldPass("odo", append(args, "delete", cmpName, "--app", appName, "--project", commonVar.Project, "-f")...) - // }) - }) + helper.Cmd("odo", "url", "create", "example-1", "--context", commonVar.Context).ShouldPass() + helper.Cmd("odo", "storage", "create", "storage-1", "--size", "1Gi", "--path", "/data1", "--context", commonVar.Context).ShouldPass() - Context("when running odo push multiple times, check for existence of environment variables", func() { - It("should should retain the same environment variable on multiple push", func() { - componentName := helper.RandString(6) - appName := helper.RandString(6) - helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context) - helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", componentName, "--app", appName, "--project", commonVar.Project, "--context", commonVar.Context)...).ShouldPass() helper.Cmd("odo", append(args, "push", "--context", commonVar.Context)...).ShouldPass() - helper.Chdir(commonVar.Context) - helper.Cmd("odo", "config", "set", "--env", "FOO=BAR").ShouldPass() - helper.Cmd("odo", append(args, "push")...).ShouldPass() - info := helper.LocalEnvInfo(commonVar.Context) - Expect(info.GetApplication(), appName) - Expect(info.GetName(), componentName) - envVars := oc.GetEnvsDevFileDeployment(componentName, appName, commonVar.Project) - val, ok := envVars["FOO"] - Expect(ok).To(BeTrue()) - Expect(val).To(Equal("BAR")) + helper.Cmd("odo", "url", "create", "example-2", "--context", commonVar.Context).ShouldPass() + helper.Cmd("odo", "storage", "create", "storage-2", "--size", "1Gi", "--path", "/data2", "--context", commonVar.Context).ShouldPass() + helper.Cmd("odo", append(args, "push", "--context", commonVar.Context)...).ShouldPass() + }) + + It("should delete the component and the owned resources", func() { + helper.Cmd("odo", append(args, "delete", "-f", "--context", commonVar.Context)...).ShouldPass() + oc.WaitAndCheckForExistence("routes", commonVar.Project, 1) + oc.WaitAndCheckForExistence("dc", commonVar.Project, 1) + oc.WaitAndCheckForExistence("pvc", commonVar.Project, 1) + oc.WaitAndCheckForExistence("bc", commonVar.Project, 1) + oc.WaitAndCheckForExistence("is", commonVar.Project, 1) + oc.WaitAndCheckForExistence("service", commonVar.Project, 1) + }) + + It("should delete the component and the owned resources with wait flag", func() { + // delete with --wait flag + helper.Cmd("odo", append(args, "delete", "-f", "-w", "--context", commonVar.Context)...).ShouldPass() + helper.VerifyResourcesDeleted(oc, []helper.ResourceInfo{ + { + ResourceType: helper.ResourceTypeRoute, + ResourceName: "example", + Namespace: commonVar.Project, + }, + { + ResourceType: helper.ResourceTypeService, + ResourceName: "example", + Namespace: commonVar.Project, + }, + { + // verify s2i pvc is delete + ResourceType: helper.ResourceTypePVC, + ResourceName: "s2idata", + Namespace: commonVar.Project, + }, + { + ResourceType: helper.ResourceTypePVC, + ResourceName: "storage-1", + Namespace: commonVar.Project, + }, + { + ResourceType: helper.ResourceTypePVC, + ResourceName: "storage-2", + Namespace: commonVar.Project, + }, + { + ResourceType: helper.ResourceTypeDeploymentConfig, + ResourceName: cmpName, + Namespace: commonVar.Project, + }, + }) }) }) - Context("Creating component with numeric named context", func() { + When("creating a component with a numeric named context", func() { + var contextNumeric string - JustBeforeEach(func() { + + BeforeEach(func() { var err error ts := time.Now().UnixNano() contextNumeric, err = ioutil.TempDir("", fmt.Sprint(ts)) Expect(err).ToNot(HaveOccurred()) }) - JustAfterEach(func() { + + AfterEach(func() { helper.DeleteDir(contextNumeric) }) It("should create default named component in a directory with numeric name", func() { helper.CopyExample(filepath.Join("source", "nodejs"), contextNumeric) - helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", "--project", commonVar.Project, "--context", contextNumeric, "--app", "testing")...).ShouldPass() + helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", "--project", commonVar.Project, "--context", contextNumeric, "--app", appName)...).ShouldPass() info := helper.LocalEnvInfo(contextNumeric) - Expect(info.GetApplication(), "testing") + Expect(info.GetApplication(), appName) helper.Cmd("odo", append(args, "push", "--context", contextNumeric, "-v4")...).ShouldPass() }) }) - Context("Creating component using symlink", func() { + When("creating a component using symlink", func() { + var symLinkPath string - JustBeforeEach(func() { + BeforeEach(func() { if runtime.GOOS == "windows" { Skip("Skipping test because for symlink creation on platform like Windows, go library needs elevated privileges.") } @@ -530,26 +560,27 @@ func componentTests(args ...string) { helper.CreateSymLink(commonVar.Context, filepath.Join(filepath.Dir(commonVar.Context), symLinkName)) symLinkPath = filepath.Join(filepath.Dir(commonVar.Context), symLinkName) }) - JustAfterEach(func() { + + AfterEach(func() { // remove the symlink err := os.Remove(symLinkPath) Expect(err).NotTo(HaveOccurred()) }) - It("Should be able to deploy a spring boot uberjar file using symlinks in all odo commands", func() { + It("should be able to deploy a spring boot uberjar file using symlinks in all odo commands", func() { oc.ImportJavaIS(commonVar.Project) helper.CopyExample(filepath.Join("binary", "java", "openjdk"), commonVar.Context) // create the component using symlink - helper.Cmd("odo", append(args, "create", "--s2i", "java:8", "sb-jar-test", "--project", + helper.Cmd("odo", append(args, "create", "--s2i", "java:8", cmpName, "--project", commonVar.Project, "--binary", filepath.Join(symLinkPath, "sb.jar"), "--context", symLinkPath)...).ShouldPass() // Create a URL and push without using the symlink helper.Cmd("odo", "url", "create", "uberjaropenjdk", "--port", "8080", "--context", symLinkPath).ShouldPass() info := helper.LocalEnvInfo(symLinkPath) Expect(info.GetApplication(), "app") - Expect(info.GetName(), "sb-jar-test") + Expect(info.GetName(), cmpName) helper.Cmd("odo", append(args, "push", "--context", symLinkPath)...).ShouldPass() routeURL := helper.DetermineRouteURL(symLinkPath) @@ -561,16 +592,16 @@ func componentTests(args ...string) { helper.Cmd("odo", append(args, "delete", "-f", "--context", symLinkPath)...).ShouldPass() }) - It("Should be able to deploy a wildfly war file using symlinks in some odo commands", func() { + It("should be able to deploy a wildfly war file using symlinks in some odo commands", func() { helper.CopyExample(filepath.Join("binary", "java", "wildfly"), commonVar.Context) - helper.Cmd("odo", append(args, "create", "--s2i", "wildfly", "javaee-war-test", "--project", + helper.Cmd("odo", append(args, "create", "--s2i", "wildfly", cmpName, "--project", commonVar.Project, "--binary", filepath.Join(symLinkPath, "ROOT.war"), "--context", symLinkPath)...).ShouldPass() // Create a URL helper.Cmd("odo", "url", "create", "warfile", "--port", "8080", "--context", commonVar.Context).ShouldPass() info := helper.LocalEnvInfo(commonVar.Context) Expect(info.GetApplication(), "app") - Expect(info.GetName(), "javaee-war-test") + Expect(info.GetName(), cmpName) helper.Cmd("odo", append(args, "push", "--context", commonVar.Context)...).ShouldPass() routeURL := helper.DetermineRouteURL(commonVar.Context) @@ -582,102 +613,17 @@ func componentTests(args ...string) { }) }) - Context("odo component delete should clean owned resources", func() { - appName := helper.RandString(5) - cmpName := helper.RandString(5) - - It("should delete the component and the owned resources", func() { - helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context) - helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", cmpName, "--app", appName, "--project", commonVar.Project, "--context", commonVar.Context)...).ShouldPass() - helper.Cmd("odo", "url", "create", "example-1", "--context", commonVar.Context).ShouldPass() - - helper.Cmd("odo", "storage", "create", "storage-1", "--size", "1Gi", "--path", "/data1", "--context", commonVar.Context).ShouldPass() - info := helper.LocalEnvInfo(commonVar.Context) - Expect(info.GetApplication(), appName) - Expect(info.GetName(), cmpName) - helper.Cmd("odo", append(args, "push", "--context", commonVar.Context)...).ShouldPass() - - helper.Cmd("odo", "url", "create", "example-2", "--context", commonVar.Context).ShouldPass() - helper.Cmd("odo", "storage", "create", "storage-2", "--size", "1Gi", "--path", "/data2", "--context", commonVar.Context).ShouldPass() - helper.Cmd("odo", append(args, "push", "--context", commonVar.Context)...).ShouldPass() - - helper.Cmd("odo", append(args, "delete", "-f", "--context", commonVar.Context)...).ShouldPass() - - oc.WaitAndCheckForExistence("routes", commonVar.Project, 1) - oc.WaitAndCheckForExistence("dc", commonVar.Project, 1) - oc.WaitAndCheckForExistence("pvc", commonVar.Project, 1) - oc.WaitAndCheckForExistence("bc", commonVar.Project, 1) - oc.WaitAndCheckForExistence("is", commonVar.Project, 1) - oc.WaitAndCheckForExistence("service", commonVar.Project, 1) - }) - - It("should delete the component and the owned resources with wait flag", func() { - helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context) - helper.Cmd("odo", append(args, "create", "--s2i", "nodejs", cmpName, "--app", appName, "--project", commonVar.Project, "--context", commonVar.Context)...).ShouldPass() - helper.Cmd("odo", "url", "create", "example-1", "--context", commonVar.Context).ShouldPass() - - helper.Cmd("odo", "storage", "create", "storage-1", "--size", "1Gi", "--path", "/data1", "--context", commonVar.Context).ShouldPass() - info := helper.LocalEnvInfo(commonVar.Context) - Expect(info.GetApplication(), appName) - Expect(info.GetName(), cmpName) - helper.Cmd("odo", append(args, "push", "--context", commonVar.Context)...).ShouldPass() - - helper.Cmd("odo", "url", "create", "example-2", "--context", commonVar.Context).ShouldPass() - helper.Cmd("odo", "storage", "create", "storage-2", "--size", "1Gi", "--path", "/data2", "--context", commonVar.Context).ShouldPass() - helper.Cmd("odo", append(args, "push", "--context", commonVar.Context)...).ShouldPass() - - // delete with --wait flag - helper.Cmd("odo", append(args, "delete", "-f", "-w", "--context", commonVar.Context)...).ShouldPass() - - helper.VerifyResourcesDeleted(oc, []helper.ResourceInfo{ - { - ResourceType: helper.ResourceTypeRoute, - ResourceName: "example", - Namespace: commonVar.Project, - }, - { - ResourceType: helper.ResourceTypeService, - ResourceName: "example", - Namespace: commonVar.Project, - }, - { - // verify s2i pvc is delete - ResourceType: helper.ResourceTypePVC, - ResourceName: "s2idata", - Namespace: commonVar.Project, - }, - { - ResourceType: helper.ResourceTypePVC, - ResourceName: "storage-1", - Namespace: commonVar.Project, - }, - { - ResourceType: helper.ResourceTypePVC, - ResourceName: "storage-2", - Namespace: commonVar.Project, - }, - { - ResourceType: helper.ResourceTypeDeploymentConfig, - ResourceName: cmpName, - Namespace: commonVar.Project, - }, - }) - }) - }) - Context("convert s2i to devfile", func() { - JustBeforeEach(func() { + BeforeEach(func() { os.Setenv("ODO_EXPERIMENTAL", "true") }) - JustAfterEach(func() { + AfterEach(func() { os.Unsetenv("ODO_EXPERIMENTAL") }) It("should convert s2i component to devfile component successfully", func() { - cmpName := "mynodejs" - appName := "app" urlName := "url1" storageName := "storage1" @@ -703,7 +649,7 @@ func componentTests(args ...string) { }) }) - Context("when components are not created/managed by odo", func() { + When("components are not created/managed by odo", func() { var runner helper.CliRunner type compStruct struct { App, Name string @@ -715,7 +661,7 @@ func componentTests(args ...string) { {"app", "example-deployment"}, } - JustBeforeEach(func() { + BeforeEach(func() { // Create resources that are not managed by odo runner = helper.GetCliRunner() dfile := filepath.Join(commonVar.Context, "deployment-app-label.yaml") @@ -730,9 +676,6 @@ func componentTests(args ...string) { compList = append(compList, compStruct{"app", "example-dc"}) } }) - JustAfterEach(func() { - // Relying on the project deletion to delete resources not managed by odo - }) // verifyListOutput verifies if the components not managed by odo are listed var verifyListOutput = func(output string, componentList []compStruct) { @@ -748,16 +691,14 @@ func componentTests(args ...string) { verifyListOutput(output, compList) }) - Context("The component has a different app name than the default 'app'", func() { - JustBeforeEach(func() { + When("the component has a different app name than the default 'app'", func() { + + BeforeEach(func() { // Create resources that are not managed by odo dfile := filepath.Join(commonVar.Context, "deployment-httpd-label.yaml") helper.CopyManifestFile("deployment-httpd-label.yaml", dfile) runner.Run("apply", "-f", dfile).Wait() }) - JustAfterEach(func() { - // relying on project deletion to delete the resources not managed by odo - }) It("should list the components with --all-apps flag", func() { output := helper.Cmd("odo", append(args, "list", "--all-apps")...).ShouldPass().Out() @@ -780,11 +721,14 @@ func componentTests(args ...string) { }) When("executing odo list from other project", func() { + var otherProject string - JustBeforeEach(func() { + + BeforeEach(func() { otherProject = commonVar.CliRunner.CreateRandNamespaceProject() }) - JustAfterEach(func() { + + AfterEach(func() { helper.Cmd("odo", "project", "set", commonVar.Project).ShouldPass() commonVar.CliRunner.DeleteNamespaceProject(otherProject) }) @@ -796,5 +740,4 @@ func componentTests(args ...string) { }) }) - }