diff --git a/pkg/odo/cli/deploy/deploy.go b/pkg/odo/cli/deploy/deploy.go index f3aa5237cf6..2ec50080699 100644 --- a/pkg/odo/cli/deploy/deploy.go +++ b/pkg/odo/cli/deploy/deploy.go @@ -95,6 +95,8 @@ func (o *DeployOptions) Complete(cmdline cmdline.Cmdline, args []string) (err er return errors.Wrap(err, "failed to update project in env.yaml file") } } + + o.clientset.KubernetesClient.SetNamespace(o.GetProject()) return } diff --git a/tests/integration/devfile/cmd_dev_test.go b/tests/integration/devfile/cmd_dev_test.go index cee35cc0de7..19e40731ec8 100644 --- a/tests/integration/devfile/cmd_dev_test.go +++ b/tests/integration/devfile/cmd_dev_test.go @@ -23,6 +23,7 @@ var _ = Describe("odo dev command tests", func() { commonVar = helper.CommonBeforeEach() cmpName = helper.RandString(6) helper.Chdir(commonVar.Context) + Expect(helper.VerifyFileExists(".odo/env/env.yaml")).To(BeFalse()) }) // This is run after every Spec (It) @@ -48,6 +49,7 @@ var _ = Describe("odo dev command tests", func() { helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context) helper.Cmd("odo", "project", "set", commonVar.Project).ShouldPass() helper.Cmd("odo", "init", "--name", cmpName, "--devfile-path", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile.yaml")).ShouldPass() + Expect(helper.VerifyFileExists(".odo/env/env.yaml")).To(BeFalse()) }) It("should show validation errors if the devfile is incorrect", func() { session := helper.CmdRunner("odo", "dev") @@ -165,5 +167,44 @@ var _ = Describe("odo dev command tests", func() { }) + When("odo dev is executed", func() { + + BeforeEach(func() { + session := helper.CmdRunner("odo", "dev") + helper.WaitForOutputToContain("Waiting for something to change", 180, 10, session) + defer session.Kill() + // An ENV file should have been created indicating current namespace + Expect(helper.VerifyFileExists(".odo/env/env.yaml")).To(BeTrue()) + helper.FileShouldContainSubstring(".odo/env/env.yaml", "Project: "+commonVar.Project) + }) + + When("deleting previous deployment and switching kubeconfig to another namespace", func() { + var otherNS string + BeforeEach(func() { + helper.Cmd("odo", "delete", "component", "--name", cmpName, "-f").ShouldPass() + output := commonVar.CliRunner.Run("get", "deployment", "-n", commonVar.Project).Err.Contents() + Expect(string(output)).To(ContainSubstring("No resources found in " + commonVar.Project + " namespace.")) + + otherNS = commonVar.CliRunner.CreateRandNamespaceProject() + }) + + AfterEach(func() { + commonVar.CliRunner.DeleteNamespaceProject(otherNS) + }) + + It("should run odo dev on initial namespace", func() { + session := helper.CmdRunner("odo", "dev") + helper.WaitForOutputToContain("Waiting for something to change", 180, 10, session) + defer session.Kill() + + output := commonVar.CliRunner.Run("get", "deployment").Err.Contents() + Expect(string(output)).To(ContainSubstring("No resources found in " + otherNS + " namespace.")) + + output = commonVar.CliRunner.Run("get", "deployment", "-n", commonVar.Project).Out.Contents() + Expect(string(output)).To(ContainSubstring(cmpName)) + }) + }) + }) + }) }) diff --git a/tests/integration/devfile/cmd_devfile_deploy_test.go b/tests/integration/devfile/cmd_devfile_deploy_test.go index 8d75afee156..fbc5baf844a 100644 --- a/tests/integration/devfile/cmd_devfile_deploy_test.go +++ b/tests/integration/devfile/cmd_devfile_deploy_test.go @@ -16,6 +16,7 @@ var _ = Describe("odo devfile deploy command tests", func() { var _ = BeforeEach(func() { commonVar = helper.CommonBeforeEach() helper.Chdir(commonVar.Context) + Expect(helper.VerifyFileExists(".odo/env/env.yaml")).To(BeFalse()) }) // This is run after every Spec (It) @@ -37,23 +38,61 @@ var _ = Describe("odo devfile deploy command tests", func() { }) When("using a devfile.yaml containing a deploy command", func() { + // from devfile + cmpName := "nodejs-prj1-api-abhz" + deploymentName := "my-component" BeforeEach(func() { helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context) helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile-deploy.yaml"), path.Join(commonVar.Context, "devfile.yaml")) }) AfterEach(func() { - helper.Cmd("odo", "v2delete", "-a").ShouldPass() + helper.Cmd("odo", "v2delete", "-af").ShouldPass() }) - It("should run odo deploy", func() { - stdout := helper.Cmd("odo", "deploy").AddEnv("PODMAN_CMD=echo").ShouldPass().Out() - By("building and pushing image to registry", func() { - Expect(stdout).To(ContainSubstring("build -t quay.io/unknown-account/myimage -f " + filepath.Join(commonVar.Context, "Dockerfile ") + commonVar.Context)) - Expect(stdout).To(ContainSubstring("push quay.io/unknown-account/myimage")) + + When("running odo deploy", func() { + var stdout string + BeforeEach(func() { + stdout = helper.Cmd("odo", "deploy").AddEnv("PODMAN_CMD=echo").ShouldPass().Out() + // An ENV file should have been created indicating current namespace + Expect(helper.VerifyFileExists(".odo/env/env.yaml")).To(BeTrue()) + helper.FileShouldContainSubstring(".odo/env/env.yaml", "Project: "+commonVar.Project) }) - By("deploying a deployment with the built image", func() { - out := commonVar.CliRunner.Run("get", "deployment", "my-component", "-n", commonVar.Project, "-o", `jsonpath="{.spec.template.spec.containers[0].image}"`).Wait().Out.Contents() - Expect(out).To(ContainSubstring("quay.io/unknown-account/myimage")) + It("should succeed", func() { + By("building and pushing image to registry", func() { + Expect(stdout).To(ContainSubstring("build -t quay.io/unknown-account/myimage -f " + filepath.Join(commonVar.Context, "Dockerfile ") + commonVar.Context)) + Expect(stdout).To(ContainSubstring("push quay.io/unknown-account/myimage")) + }) + By("deploying a deployment with the built image", func() { + out := commonVar.CliRunner.Run("get", "deployment", deploymentName, "-n", commonVar.Project, "-o", `jsonpath="{.spec.template.spec.containers[0].image}"`).Wait().Out.Contents() + Expect(out).To(ContainSubstring("quay.io/unknown-account/myimage")) + }) + }) + + When("deleting previous deployment and switching kubeconfig to another namespace", func() { + var otherNS string + BeforeEach(func() { + helper.Cmd("odo", "delete", "component", "--name", cmpName, "-f").ShouldPass() + output := commonVar.CliRunner.Run("get", "deployment", "-n", commonVar.Project).Err.Contents() + Expect(string(output)).To(ContainSubstring("No resources found in " + commonVar.Project + " namespace.")) + + otherNS = commonVar.CliRunner.CreateRandNamespaceProject() + }) + + AfterEach(func() { + commonVar.CliRunner.DeleteNamespaceProject(otherNS) + }) + + It("should run odo deploy on initial namespace", func() { + helper.Cmd("odo", "deploy").AddEnv("PODMAN_CMD=echo").ShouldPass() + + output := commonVar.CliRunner.Run("get", "deployment").Err.Contents() + Expect(string(output)).To(ContainSubstring("No resources found in " + otherNS + " namespace.")) + + output = commonVar.CliRunner.Run("get", "deployment", "-n", commonVar.Project).Out.Contents() + Expect(string(output)).To(ContainSubstring(deploymentName)) + }) + }) }) }) diff --git a/tests/integration/devfile/cmd_devfile_init_test.go b/tests/integration/devfile/cmd_devfile_init_test.go index 15df02d03a8..677cb5e8a97 100644 --- a/tests/integration/devfile/cmd_devfile_init_test.go +++ b/tests/integration/devfile/cmd_devfile_init_test.go @@ -18,6 +18,7 @@ var _ = Describe("odo devfile init command tests", func() { var _ = BeforeEach(func() { commonVar = helper.CommonBeforeEach() helper.Chdir(commonVar.Context) + Expect(helper.VerifyFileExists(".odo/env/env.yaml")).To(BeFalse()) }) var _ = AfterEach(func() {