From ffb78207d769f421d41654e4a734450a481e3cef Mon Sep 17 00:00:00 2001 From: Girish Ramnani Date: Thu, 10 Oct 2019 15:26:45 +0530 Subject: [PATCH] resolved failing tests --- tests/helper/helper_generic.go | 16 ++++++++++++++++ tests/integration/component.go | 13 +++++++++---- tests/integration/project/cmd_project_test.go | 6 ++++-- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/tests/helper/helper_generic.go b/tests/helper/helper_generic.go index 2841978aa03..9f1a6813195 100644 --- a/tests/helper/helper_generic.go +++ b/tests/helper/helper_generic.go @@ -1,6 +1,7 @@ package helper import ( + "encoding/json" "fmt" "math/rand" "strings" @@ -63,3 +64,18 @@ func DontMatchAllInOutput(output string, tonotmatch []string) { Expect(output).ToNot(ContainSubstring(i)) } } + +// Unindented returns the unindented version of the jsonStr passed to it +func Unindented(jsonStr string) (string, error) { + var tmpMap map[string]interface{} + err := json.Unmarshal([]byte(jsonStr), &tmpMap) + if err != nil { + return "", err + } + + obj, err := json.Marshal(tmpMap) + if err != nil { + return "", err + } + return string(obj), err +} diff --git a/tests/integration/component.go b/tests/integration/component.go index 72cf935e0c8..d0e0ce439fc 100644 --- a/tests/integration/component.go +++ b/tests/integration/component.go @@ -108,7 +108,8 @@ func componentTests(args ...string) { contextPath = strings.TrimSpace(context) } desired := fmt.Sprintf(`{"kind":"Component","apiVersion":"odo.openshift.io/v1alpha1","metadata":{"name":"nodejs","namespace":"%s","creationTimestamp":null},"spec":{"app":"app","type":"nodejs","source":"./","ports":["8080/TCP"]},"status":{"context":"%s","state":"Not Pushed"}}`, project, contextPath) - actual := helper.CmdShouldPass("odo", append(args, "list", "-o", "json", "--path", filepath.Dir(context))...) + actual, err := helper.Unindented(helper.CmdShouldPass("odo", append(args, "list", "-o", "json", "--path", filepath.Dir(context))...)) + Expect(err).Should(BeNil()) // since the tests are run parallel, there might be many odo component directories in the root folder // so we only check for the presence of the current one Expect(actual).Should(ContainSubstring(desired)) @@ -136,12 +137,16 @@ func componentTests(args ...string) { contextPath2 = strings.TrimSpace(context2) } - actual := helper.CmdShouldPass("odo", append(args, "list", "-o", "json", "--path", filepath.Dir(context))...) + actual, err := helper.Unindented(helper.CmdShouldPass("odo", append(args, "list", "-o", "json", "--path", filepath.Dir(context))...)) + Expect(err).Should(BeNil()) helper.Chdir(context) helper.DeleteDir(context2) helper.DeleteProject(project2) - Expect(actual).Should(ContainSubstring(fmt.Sprintf(`{"kind":"Component","apiVersion":"odo.openshift.io/v1alpha1","metadata":{"name":"nodejs","namespace":"%s","creationTimestamp":null},"spec":{"app":"app","type":"nodejs","source":"./","ports":["8080/TCP"]},"status":{"context":"%s","state":"Pushed"}}`, project, contextPath))) - Expect(actual).Should(ContainSubstring(fmt.Sprintf(`{"kind":"Component","apiVersion":"odo.openshift.io/v1alpha1","metadata":{"name":"python","namespace":"%s","creationTimestamp":null},"spec":{"app":"app","type":"python","source":"./","ports":["8080/TCP"]},"status":{"context":"%s","state":"Pushed"}}`, project2, contextPath2))) + expected := fmt.Sprintf(`{"kind":"Component","apiVersion":"odo.openshift.io/v1alpha1","metadata":{"name":"nodejs","namespace":"%s","creationTimestamp":null},"spec":{"app":"app","type":"nodejs","source":"./","ports":["8080/TCP"]},"status":{"context":"%s","state":"Pushed"}}`, project, contextPath) + Expect(actual).Should(ContainSubstring(expected)) + expected = fmt.Sprintf(`{"kind":"Component","apiVersion":"odo.openshift.io/v1alpha1","metadata":{"name":"python","namespace":"%s","creationTimestamp":null},"spec":{"app":"app","type":"python","source":"./","ports":["8080/TCP"]},"status":{"context":"%s","state":"Pushed"}}`, project2, contextPath2) + Expect(actual).Should(ContainSubstring(expected)) + }) It("should create the component from the branch ref when provided", func() { diff --git a/tests/integration/project/cmd_project_test.go b/tests/integration/project/cmd_project_test.go index 2ba49f5b630..45183ca1338 100644 --- a/tests/integration/project/cmd_project_test.go +++ b/tests/integration/project/cmd_project_test.go @@ -44,8 +44,10 @@ var _ = Describe("odo project command tests", func() { Expect(listOutput).To(ContainSubstring(project)) // project deletion doesn't happen immediately, so we test subset of the string - listOutputJson := helper.CmdShouldPass("odo", "project", "list", "-o", "json") - Expect(listOutputJson).To(ContainSubstring(`{"kind":"Project","apiVersion":"odo.openshift.io/v1alpha1","metadata":{"name":"` + project + `","namespace":"` + project + `","creationTimestamp":null},"spec":{},"status":{"active":true}}`)) + listOutputJSON, err := helper.Unindented(helper.CmdShouldPass("odo", "project", "list", "-o", "json")) + Expect(err).Should(BeNil()) + expected := `{"kind":"Project","apiVersion":"odo.openshift.io/v1alpha1","metadata":{"name":"` + project + `","namespace":"` + project + `","creationTimestamp":null},"spec":{},"status":{"active":true}}` + Expect(listOutputJSON).To(ContainSubstring(expected)) }) }) })