Skip to content

Commit

Permalink
Add integration test for odo dev/deploy when not connected to a clust…
Browse files Browse the repository at this point in the history
…er or podman

Signed-off-by: Parthvi Vala <[email protected]>
Co-authored-by: Armel Soro <[email protected]>
Signed-off-by: Parthvi Vala <[email protected]>
  • Loading branch information
valaparthvi and rm3l committed Mar 28, 2023
1 parent 4a9636d commit 009a504
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 37 deletions.
52 changes: 28 additions & 24 deletions tests/integration/cmd_dev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,40 @@ var _ = Describe("odo dev command tests", func() {
})
})

When("a component is bootstrapped and pushed", func() {
When("a component is bootstrapped", func() {
BeforeEach(func() {
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context)
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 fail to run odo dev when not connected to any cluster", Label(helper.LabelNoCluster), func() {
errOut := helper.Cmd("odo", "dev").ShouldFail().Err()
Expect(errOut).To(ContainSubstring("unable to access the cluster"))
})
It("should fail to run odo dev when podman is nil", Label(helper.LabelPodman), func() {
errOut := helper.Cmd("odo", "dev", "--platform", "podman").WithEnv("PODMAN_CMD=echo").ShouldFail().Err()
Expect(errOut).To(ContainSubstring("unable to access podman"))
})
When("using a default namespace", func() {
BeforeEach(func() {
commonVar.CliRunner.SetProject("default")
})
AfterEach(func() {
commonVar.CliRunner.SetProject(commonVar.Project)
})
It("should print warning about default namespace when running odo dev", func() {
namespace := "project"
if helper.IsKubernetesCluster() {
namespace = "namespace"
}
err := helper.RunDevMode(helper.DevSessionOpts{}, func(session *gexec.Session, outContents []byte, errContents []byte, ports map[string]string) {
Expect(string(errContents)).To(ContainSubstring(fmt.Sprintf("You are using \"default\" %[1]s, odo may not work as expected in the default %[1]s.", namespace)))
})
Expect(err).ToNot(HaveOccurred())
})
})

It("should add annotation to use ImageStreams", func() {
// #6376
err := helper.RunDevMode(helper.DevSessionOpts{}, func(session *gexec.Session, outContents, errContents []byte, ports map[string]string) {
Expand Down Expand Up @@ -2659,29 +2686,6 @@ CMD ["npm", "start"]
}))
}

Context("using a default namespace", func() {
BeforeEach(func() {
commonVar.CliRunner.SetProject("default")
})
AfterEach(func() {
commonVar.CliRunner.SetProject(commonVar.Project)
})
When("a component is created", func() {
BeforeEach(func() {
helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context)
helper.Cmd("odo", "init", "--name", cmpName, "--devfile-path", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile.yaml")).ShouldPass()
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context)
})
It("should print warning about default namespace when running odo dev", func() {
namespace := "project"
if helper.IsKubernetesCluster() {
namespace = "namespace"
}
helper.WaitForDevModeToContain(helper.DevSessionOpts{}, fmt.Sprintf("You are using \"default\" %[1]s, odo may not work as expected in the default %[1]s.", namespace), true)
})
})
})

// Test reused and adapted from the now-removed `cmd_devfile_delete_test.go`.
// cf. https://github.com/redhat-developer/odo/blob/24fd02673d25eb4c7bb166ec3369554a8e64b59c/tests/integration/devfile/cmd_devfile_delete_test.go#L172-L238
When("a component with endpoints is bootstrapped and pushed", func() {
Expand Down
27 changes: 14 additions & 13 deletions tests/integration/cmd_devfile_deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,20 @@ var _ = Describe("odo devfile deploy command tests", func() {

})
})
When("using a default namespace", func() {
When("a component is bootstrapped", func() {
BeforeEach(func() {
commonVar.CliRunner.SetProject("default")
})
AfterEach(func() {
helper.Cmd("odo", "delete", "component", "-f").ShouldPass()
commonVar.CliRunner.SetProject(commonVar.Project)
helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context)
helper.Cmd("odo", "init", "--name", cmpName, "--devfile-path", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile-deploy.yaml")).ShouldPass()
})
When("deploying a devfile with deploy command", func() {
When("using a default namespace", func() {
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"),
helper.DevfileMetadataNameSetter(cmpName))
commonVar.CliRunner.SetProject("default")
})
AfterEach(func() {
helper.Cmd("odo", "delete", "component", "-f").ShouldPass()
commonVar.CliRunner.SetProject(commonVar.Project)
})

It("should display warning when running the deploy command", func() {
errOut := helper.Cmd("odo", "deploy").AddEnv("PODMAN_CMD=echo").ShouldRun().Err()
namespace := "project"
Expand All @@ -68,7 +66,10 @@ var _ = Describe("odo devfile deploy command tests", func() {
Expect(errOut).To(ContainSubstring(fmt.Sprintf("You are using \"default\" %[1]s, odo may not work as expected in the default %[1]s.", namespace)))
})
})

It("should fail to run odo deploy when not connected to any cluster", Label(helper.LabelNoCluster), func() {
errOut := helper.Cmd("odo", "deploy").ShouldFail().Err()
Expect(errOut).To(ContainSubstring("unable to access the cluster"))
})
})
for _, ctx := range []struct {
title string
Expand Down

0 comments on commit 009a504

Please sign in to comment.