Skip to content

Commit

Permalink
Fixes list and describe of secure URLs for not pushed components
Browse files Browse the repository at this point in the history
  • Loading branch information
mik-dass committed May 29, 2020
1 parent 46ea6c3 commit d8a7283
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
5 changes: 3 additions & 2 deletions pkg/url/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ func List(client *occlient.Client, localConfig *config.LocalConfigInfo, componen

for _, configURL := range localConfigURLs {
localURL := ConvertConfigURL(configURL)
var found bool = false
var found = false
for _, r := range routes {
clusterURL := getMachineReadableFormat(r)
if localURL.Name == clusterURL.Name {
Expand Down Expand Up @@ -536,7 +536,8 @@ func ConvertConfigURL(configURL config.ConfigURL) URL {
Name: configURL.Name,
},
Spec: URLSpec{
Port: configURL.Port,
Port: configURL.Port,
Secure: configURL.Secure,
},
}
}
Expand Down
32 changes: 28 additions & 4 deletions tests/integration/cmd_url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,18 @@ var _ = Describe("odo url command tests", func() {
helper.CopyExample(filepath.Join("source", "nodejs"), context)
helper.CmdShouldPass("odo", "create", "nodejs", "--context", context, "--project", project, componentName)

helper.CmdShouldPass("odo", "url", "create", url1, "--port", "8080", "--context", context, "--secure")
stdout := helper.CmdShouldPass("odo", "url", "create", url1, "--port", "8080", "--context", context, "--secure")

stdout = helper.CmdShouldPass("odo", "url", "list", "--context", context)
helper.MatchAllInOutput(stdout, []string{url1, "Not Pushed", "true"})

helper.CmdShouldPass("odo", "push", "--context", context)

secureURL := helper.DetermineRouteURL(context)
Expect(secureURL).To(ContainSubstring("https:"))
helper.HttpWaitFor(secureURL, "Hello world from node.js!", 20, 1)

stdout := helper.CmdShouldPass("odo", "url", "list", "--context", context)
stdout = helper.CmdShouldPass("odo", "url", "list", "--context", context)
helper.MatchAllInOutput(stdout, []string{secureURL, "Pushed", "true"})

helper.CmdShouldPass("odo", "delete", "-f", "--context", context)
Expand All @@ -111,6 +115,22 @@ var _ = Describe("odo url command tests", func() {
stdout = helper.CmdShouldPass("odo", "url", "describe", url1, "--context", context)
helper.MatchAllInOutput(stdout, []string{url1, "Locally Deleted", url1, "odo push"})
})

It("should be able to describe a url in CLI format and machine readable json format for a secure url", func() {
helper.CmdShouldPass("odo", "create", "nodejs", "nodejs", "--app", "myapp", "--project", project, "--git", "https://github.com/openshift/nodejs-ex", "--context", context)
helper.CmdShouldPass("odo", "url", "create", "myurl", "--secure", "--context", context)

actualURLDescribeJSON := helper.CmdShouldPass("odo", "url", "describe", "myurl", "-o", "json", "--context", context)
desiredURLDescribeJSON := fmt.Sprintf(`{"kind":"url","apiVersion":"odo.dev/v1alpha1","metadata":{ "name": "myurl","creationTimestamp": null},"spec":{ "port": 8080,"secure": true},"status": {"state": "Not Pushed"}}`)
Expect(desiredURLDescribeJSON).Should(MatchJSON(actualURLDescribeJSON))

helper.CmdShouldPass("odo", "push", "--context", context)

// odo url describe -o json
actualURLDescribeJSON = helper.CmdShouldPass("odo", "url", "describe", "myurl", "-o", "json", "--context", context)
desiredURLDescribeJSON = fmt.Sprintf(`{"kind":"url","apiVersion":"odo.dev/v1alpha1","metadata":{ "name": "myurl","creationTimestamp": null},"spec":{ "port": 8080,"secure": true},"status": {"state": "Pushed"}}`)
Expect(desiredURLDescribeJSON).Should(MatchJSON(actualURLDescribeJSON))
})
})

Context("when listing urls using -o json flag", func() {
Expand Down Expand Up @@ -138,13 +158,17 @@ var _ = Describe("odo url command tests", func() {
It("should be able to list url in machine readable json format for a secure url", func() {
helper.CmdShouldPass("odo", "create", "nodejs", "nodejs", "--app", "myapp", "--project", project, "--git", "https://github.com/openshift/nodejs-ex")
helper.CmdShouldPass("odo", "url", "create", "myurl", "--secure")
actualURLListJSON := helper.CmdShouldPass("odo", "url", "list", "-o", "json")
desiredURLListJSON := fmt.Sprintf(`{"kind":"List","apiVersion":"odo.dev/v1alpha1","metadata":{},"items":[{"kind":"url","apiVersion":"odo.dev/v1alpha1","metadata":{"name":"myurl","creationTimestamp":null},"spec":{"port":8080,"secure":true},"status":{"state": "Not Pushed"}}]}`)
Expect(desiredURLListJSON).Should(MatchJSON(actualURLListJSON))

helper.CmdShouldPass("odo", "push")

// odo url list -o json
actualURLListJSON := helper.CmdShouldPass("odo", "url", "list", "-o", "json")
actualURLListJSON = helper.CmdShouldPass("odo", "url", "list", "-o", "json")
fullURLPath := helper.DetermineRouteURL("")
pathNoHTTP := strings.Split(fullURLPath, "//")[1]
desiredURLListJSON := fmt.Sprintf(`{"kind":"List","apiVersion":"odo.dev/v1alpha1","metadata":{},"items":[{"kind":"url","apiVersion":"odo.dev/v1alpha1","metadata":{"name":"myurl","creationTimestamp":null},"spec":{"host":"%s","protocol":"https","port":8080,"secure":true},"status":{"state": "Pushed"}}]}`, pathNoHTTP)
desiredURLListJSON = fmt.Sprintf(`{"kind":"List","apiVersion":"odo.dev/v1alpha1","metadata":{},"items":[{"kind":"url","apiVersion":"odo.dev/v1alpha1","metadata":{"name":"myurl","creationTimestamp":null},"spec":{"host":"%s","protocol":"https","port":8080,"secure":true},"status":{"state": "Pushed"}}]}`, pathNoHTTP)
Expect(desiredURLListJSON).Should(MatchJSON(actualURLListJSON))
})
})
Expand Down

0 comments on commit d8a7283

Please sign in to comment.