Skip to content

Commit

Permalink
Test and fix using namespace from env file (redhat-developer#5545)
Browse files Browse the repository at this point in the history
* Test and fix using namespace from env file

* Review

* Delete other NS at the end of test
  • Loading branch information
feloy authored Mar 14, 2022
1 parent 64f334f commit ca1a55d
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 9 deletions.
2 changes: 2 additions & 0 deletions pkg/odo/cli/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
41 changes: 41 additions & 0 deletions tests/integration/devfile/cmd_dev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand Down Expand Up @@ -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))
})
})
})

})
})
57 changes: 48 additions & 9 deletions tests/integration/devfile/cmd_devfile_deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
})

})
})
})
Expand Down
1 change: 1 addition & 0 deletions tests/integration/devfile/cmd_devfile_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit ca1a55d

Please sign in to comment.