Skip to content

Commit

Permalink
resolved failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
girishramnani committed Oct 10, 2019
1 parent 4e93514 commit ffb7820
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
16 changes: 16 additions & 0 deletions tests/helper/helper_generic.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package helper

import (
"encoding/json"
"fmt"
"math/rand"
"strings"
Expand Down Expand Up @@ -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
}
13 changes: 9 additions & 4 deletions tests/integration/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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() {
Expand Down
6 changes: 4 additions & 2 deletions tests/integration/project/cmd_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
})
})

0 comments on commit ffb7820

Please sign in to comment.