Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with describe/list binding tests #6839

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/odo/cli/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ func (lo *ListOptions) Complete(ctx context.Context, cmdline cmdline.Cmdline, ar
} else if lo.clientset.KubernetesClient != nil {
lo.namespaceFilter = odocontext.GetNamespace(ctx)
}
// Set the namespace; this ensures we fetch resources from the given namespace
if lo.clientset.KubernetesClient != nil {
lo.clientset.KubernetesClient.SetNamespace(lo.namespaceFilter)
}

return nil
}
Expand Down
53 changes: 38 additions & 15 deletions tests/integration/cmd_describe_list_binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var _ = Describe("odo describe/list binding command tests", func() {
When(fmt.Sprintf("creating a component with a binding (service in namespace %q)", ns), func() {
cmpName := "my-nodejs-app"
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-with-service-binding-files.yaml")).ShouldPass()
if ns != "" {
helper.ReplaceString(filepath.Join(commonVar.Context, "devfile.yaml"),
Expand Down Expand Up @@ -92,7 +93,7 @@ var _ = Describe("odo describe/list binding command tests", func() {
{"list"},
} {
command := command
It(fmt.Sprintf("should list the binding without running odo dev (%v)", command), func() {
It(fmt.Sprintf("should list the binding without running odo dev (%s)", command), func() {
By("JSON output", func() {
res := helper.Cmd("odo", append(command, "-o", "json")...).ShouldPass()
stdout, stderr := res.Out(), res.Err()
Expand Down Expand Up @@ -157,7 +158,7 @@ var _ = Describe("odo describe/list binding command tests", func() {
assertDescribeNamedJsonOutput func(stdout, stderr string, name string)
assertDescribeNamedHumanReadableOutput func(stdout, stderr string, name string)
assertListJsonOutput func(devfile bool, stdout, stderr string)
assertListHumanReadableOutput func(devfile bool, stdout, stderr string)
assertListHumanReadableOutput func(devfile bool, stdout, stderr string, command []string)
}{
{
title: "creating a component with a binding as files",
Expand Down Expand Up @@ -269,9 +270,14 @@ var _ = Describe("odo describe/list binding command tests", func() {

helper.JsonPathContentIs(stdout, "bindings.1.name", "my-nodejs-app-cluster-sample-ocp")
},
assertListHumanReadableOutput: func(devfile bool, stdout, stderr string) {
assertListHumanReadableOutput: func(devfile bool, stdout, stderr string, command []string) {
lines := strings.Split(stdout, "\n")
Expect(lines[0]).To(ContainSubstring("Listing ServiceBindings"))
if len(command) == 1 {
Expect(lines[0]).To(ContainSubstring(fmt.Sprintf("Listing resources from the namespace %q", commonVar.Project)))
lines = lines[6:]
} else {
Expect(lines[0]).To(ContainSubstring("Listing ServiceBindings"))
}
if devfile {
Expect(lines[3]).To(ContainSubstring("* "))
} else {
Expand Down Expand Up @@ -401,9 +407,14 @@ var _ = Describe("odo describe/list binding command tests", func() {
helper.JsonPathContentIs(stdout, "bindings.1.name", "my-nodejs-app-cluster-sample-ocp")

},
assertListHumanReadableOutput: func(devfile bool, stdout, stderr string) {
assertListHumanReadableOutput: func(devfile bool, stdout, stderr string, command []string) {
lines := strings.Split(stdout, "\n")
Expect(lines[0]).To(ContainSubstring("Listing ServiceBindings"))
if len(command) == 1 {
Expect(lines[0]).To(ContainSubstring(fmt.Sprintf("Listing resources from the namespace %q", commonVar.Project)))
lines = lines[6:]
} else {
Expect(lines[0]).To(ContainSubstring("Listing ServiceBindings"))
}
if devfile {
Expect(lines[3]).To(ContainSubstring("* "))
} else {
Expand Down Expand Up @@ -513,9 +524,14 @@ var _ = Describe("odo describe/list binding command tests", func() {

helper.JsonPathContentIs(stdout, "bindings.1.name", "my-nodejs-app-cluster-sample-ocp")
},
assertListHumanReadableOutput: func(devfile bool, stdout, stderr string) {
assertListHumanReadableOutput: func(devfile bool, stdout, stderr string, command []string) {
lines := strings.Split(stdout, "\n")
Expect(lines[0]).To(ContainSubstring("Listing ServiceBindings"))
if len(command) == 1 {
Expect(lines[0]).To(ContainSubstring(fmt.Sprintf("Listing resources from the namespace %q", commonVar.Project)))
lines = lines[6:]
} else {
Expect(lines[0]).To(ContainSubstring("Listing ServiceBindings"))
}
if devfile {
Expect(lines[3]).To(ContainSubstring("* "))
} else {
Expand Down Expand Up @@ -622,9 +638,14 @@ var _ = Describe("odo describe/list binding command tests", func() {

helper.JsonPathContentIs(stdout, "bindings.1.name", "my-nodejs-app-cluster-sample-ocp")
},
assertListHumanReadableOutput: func(devfile bool, stdout, stderr string) {
assertListHumanReadableOutput: func(devfile bool, stdout, stderr string, command []string) {
lines := strings.Split(stdout, "\n")
Expect(lines[0]).To(ContainSubstring("Listing ServiceBindings"))
if len(command) == 1 {
Expect(lines[0]).To(ContainSubstring(fmt.Sprintf("Listing resources from the namespace %q", commonVar.Project)))
lines = lines[6:]
} else {
Expect(lines[0]).To(ContainSubstring("Listing ServiceBindings"))
}
if devfile {
Expect(lines[3]).To(ContainSubstring("* "))
} else {
Expand All @@ -645,6 +666,7 @@ var _ = Describe("odo describe/list binding command tests", func() {
When(fmt.Sprintf("%s (service in namespace %q)", ctx.title, ns), func() {
cmpName := "my-nodejs-app"
BeforeEach(func() {
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context)
helper.Cmd("odo", "init", "--name", cmpName, "--devfile-path", ctx.devfile).ShouldPass()
})

Expand Down Expand Up @@ -739,7 +761,8 @@ var _ = Describe("odo describe/list binding command tests", func() {
{"list"},
{"list", "binding"},
} {
It("should list the binding", func() {
command := command
It(fmt.Sprintf("should list the binding - command: %v", command), func() {
By("JSON output", func() {
res := helper.Cmd("odo", append(command, "-o", "json")...).ShouldPass()
stdout, stderr := res.Out(), res.Err()
Expand All @@ -751,7 +774,7 @@ var _ = Describe("odo describe/list binding command tests", func() {
res := helper.Cmd("odo", command...).ShouldPass()
stdout, stderr := res.Out(), res.Err()
if ctx.assertListHumanReadableOutput != nil {
ctx.assertListHumanReadableOutput(true, stdout, stderr)
ctx.assertListHumanReadableOutput(true, stdout, stderr, command)
}
})

Expand All @@ -770,7 +793,7 @@ var _ = Describe("odo describe/list binding command tests", func() {
res := helper.Cmd("odo", command...).ShouldPass()
stdout, stderr := res.Out(), res.Err()
if ctx.assertListHumanReadableOutput != nil {
ctx.assertListHumanReadableOutput(false, stdout, stderr)
ctx.assertListHumanReadableOutput(false, stdout, stderr, command)
}
})
})
Expand All @@ -784,7 +807,7 @@ var _ = Describe("odo describe/list binding command tests", func() {
commonVar.CliRunner.SetProject(commonVar.Project)
})

It("should list the binding with --namespace flag", func() {
It(fmt.Sprintf("should list the binding with --namespace flag - command: %s", command), func() {
By("JSON output from another directory", func() {
err := os.Chdir("/")
Expect(err).ToNot(HaveOccurred())
Expand All @@ -800,7 +823,7 @@ var _ = Describe("odo describe/list binding command tests", func() {
res := helper.Cmd("odo", append(command, "--namespace", commonVar.Project)...).ShouldPass()
stdout, stderr := res.Out(), res.Err()
if ctx.assertListHumanReadableOutput != nil {
ctx.assertListHumanReadableOutput(false, stdout, stderr)
ctx.assertListHumanReadableOutput(false, stdout, stderr, command)
}
})
})
Expand Down