Skip to content

Commit

Permalink
Review
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy committed May 3, 2022
1 parent 9923c39 commit fc6d6b9
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
4 changes: 1 addition & 3 deletions .ibm/images/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ RUN curl -fsSL https://clis.cloud.ibm.com/install/linux | sh && \
rm -rf /var/lib/apt/lists/*

# Create non-root user and associated home directory
RUN useradd -u 2001 tester
RUN mkdir /home/tester
RUN chown tester:tester /home/tester
RUN useradd -u 2001 --create-home tester
# Change to non-root privilege
USER tester

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ components:
### State file
When the command `odo dev` is executed, the state of the command is saved in the file `./.odo/state.json`.
When the command `odo dev` is executed, the state of the command is saved in the file `./.odo/devstate.json`.
This state file contains the PID of the `odo dev` running process (`0` if no command is running), the timestamp
at which the state has been last saved, and the currently forwarded ports.
Expand Down
16 changes: 9 additions & 7 deletions tests/helper/helper_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,23 +258,25 @@ func CommonAfterEach(commonVar CommonVar) {
}

// JsonPathContentIs expects that the content of the path to equal value
func JsonPathContentIs(json string, path string, value string) bool {
func JsonPathContentIs(json string, path string, value string) {
result := gjson.Get(json, path)
Expect(result.String()).To(Equal(value), fmt.Sprintf("content of path %q should be %q but is %q", path, value, result.String()))
return true
}

// JsonPathContentContain expects that the content of the path to contain value
func JsonPathContentContain(json string, path string, value string) bool {
func JsonPathContentContain(json string, path string, value string) {
result := gjson.Get(json, path)
Expect(result.String()).To(ContainSubstring(value), fmt.Sprintf("content of path %q should contain %q but is %q", path, value, result.String()))
return true
}

func JsonPathContentMatch(json string, path string, regexp string) bool {
func JsonPathContentIsValidUserPort(json string, path string) {
result := gjson.Get(json, path)
Expect(result.String()).To(MatchRegexp(regexp), fmt.Sprintf("content of path %q should match %q but is %q", path, regexp, result.String()))
return true
intVal, err := strconv.Atoi(result.String())
Expect(err).ToNot(HaveOccurred())
Expect(intVal).To(SatisfyAll(
BeNumerically(">=", 1024),
BeNumerically("<=", 65535),
))
}

// SetProjectName sets projectNames based on the neame of the test file name (withouth path and replacing _ with -), line number of current ginkgo execution, and a random string of 3 letters
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/devfile/cmd_alizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ var _ = Describe("odo alizer command tests", func() {
stdout, stderr := res.Out(), res.Err()
Expect(stderr).To(BeEmpty())
Expect(helper.IsJSON(stdout)).To(BeTrue())
Expect(helper.JsonPathContentIs(stdout, "devfile", "nodejs"))
Expect(helper.JsonPathContentIs(stdout, "devfileRegistry", "DefaultDevfileRegistry"))
helper.JsonPathContentIs(stdout, "devfile", "nodejs")
helper.JsonPathContentIs(stdout, "devfileRegistry", "DefaultDevfileRegistry")
})
})

Expand All @@ -43,7 +43,7 @@ var _ = Describe("odo alizer command tests", func() {
stdout, stderr := res.Out(), res.Err()
Expect(stdout).To(BeEmpty())
Expect(helper.IsJSON(stderr)).To(BeTrue())
Expect(helper.JsonPathContentContain(stderr, "message", "No valid devfile found for project in"))
helper.JsonPathContentContain(stderr, "message", "No valid devfile found for project in")
})

It("alizer should fail without json output", func() {
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/devfile/cmd_dev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1445,8 +1445,8 @@ var _ = Describe("odo dev command tests", func() {
helper.JsonPathContentIs(string(contentJSON), "forwardedPorts.1.localAddress", "127.0.0.1")
helper.JsonPathContentIs(string(contentJSON), "forwardedPorts.0.containerPort", "3000")
helper.JsonPathContentIs(string(contentJSON), "forwardedPorts.1.containerPort", "4567")
helper.JsonPathContentMatch(string(contentJSON), "forwardedPorts.0.localPort", "[0-9]+")
helper.JsonPathContentMatch(string(contentJSON), "forwardedPorts.1.localPort", "[0-9]+")
helper.JsonPathContentIsValidUserPort(string(contentJSON), "forwardedPorts.0.localPort")
helper.JsonPathContentIsValidUserPort(string(contentJSON), "forwardedPorts.1.localPort")
})

When("odo dev is stopped", func() {
Expand Down
16 changes: 8 additions & 8 deletions tests/integration/devfile/cmd_devfile_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ var _ = Describe("odo devfile init command tests", func() {
stdout, stderr := res.Out(), res.Err()
Expect(stdout).To(BeEmpty())
Expect(helper.IsJSON(stderr)).To(BeTrue())
Expect(helper.JsonPathContentIs(stderr, "message", "parameters are expected to select a devfile"))
helper.JsonPathContentIs(stderr, "message", "parameters are expected to select a devfile")
})

By("running odo init with incomplete flags and JSON output", func() {
res := helper.Cmd("odo", "init", "--name", "aname", "-o", "json").ShouldFail()
stdout, stderr := res.Out(), res.Err()
Expect(stdout).To(BeEmpty())
Expect(helper.IsJSON(stderr)).To(BeTrue())
Expect(helper.JsonPathContentContain(stderr, "message", "either --devfile or --devfile-path parameter should be specified"))
helper.JsonPathContentContain(stderr, "message", "either --devfile or --devfile-path parameter should be specified")
})

By("keeping an empty directory when running odo init with wrong starter name", func() {
Expand Down Expand Up @@ -124,12 +124,12 @@ var _ = Describe("odo devfile init command tests", func() {
stdout, stderr := res.Out(), res.Err()
Expect(stderr).To(BeEmpty())
Expect(helper.IsJSON(stdout)).To(BeTrue())
Expect(helper.JsonPathContentIs(stdout, "devfilePath", filepath.Join(commonVar.Context, "devfile.yaml")))
Expect(helper.JsonPathContentIs(stdout, "devfileData.devfile.schemaVersion", "2.0.0"))
Expect(helper.JsonPathContentIs(stdout, "devfileData.supportedOdoFeatures.dev", "true"))
Expect(helper.JsonPathContentIs(stdout, "devfileData.supportedOdoFeatures.debug", "false"))
Expect(helper.JsonPathContentIs(stdout, "devfileData.supportedOdoFeatures.deploy", "false"))
Expect(helper.JsonPathContentIs(stdout, "managedBy", "odo"))
helper.JsonPathContentIs(stdout, "devfilePath", filepath.Join(commonVar.Context, "devfile.yaml"))
helper.JsonPathContentIs(stdout, "devfileData.devfile.schemaVersion", "2.0.0")
helper.JsonPathContentIs(stdout, "devfileData.supportedOdoFeatures.dev", "true")
helper.JsonPathContentIs(stdout, "devfileData.supportedOdoFeatures.debug", "false")
helper.JsonPathContentIs(stdout, "devfileData.supportedOdoFeatures.deploy", "false")
helper.JsonPathContentIs(stdout, "managedBy", "odo")
})
})
When("using --devfile-path flag with a local devfile", func() {
Expand Down

0 comments on commit fc6d6b9

Please sign in to comment.