From d74f1b472ed78b8906ddc0243d2faefecbef8028 Mon Sep 17 00:00:00 2001 From: Shawn Neal Date: Wed, 28 Oct 2020 12:14:39 -0700 Subject: [PATCH 1/2] Add support for curling v3 links --- cf/cf.go | 13 +++++++++++-- cf/cf_test.go | 13 +++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/cf/cf.go b/cf/cf.go index a0b59cd..93deb91 100644 --- a/cf/cf.go +++ b/cf/cf.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "fmt" + "net/url" "strings" plugin_models "code.cloudfoundry.org/cli/plugin/models" @@ -185,8 +186,16 @@ func (cf *CF) GetAppInfo(appName string) (appGuid, appState, appStack string, er return app.GUID, app.State, app.Lifecycle.Data.Stack, nil } -func (cf *CF) CFCurl(args ...string) ([]string, error) { - curlArgs := append([]string{"curl"}, args...) +func (cf *CF) CFCurl(path string, args ...string) ([]string, error) { + u, err := url.Parse(path) + if err != nil { + return nil, err + } + u.Scheme = "" + u.Host = "" + + curlArgs := []string{"curl", u.String()} + curlArgs = append(curlArgs, args...) output, err := cf.Conn.CliCommandWithoutTerminalOutput(curlArgs...) if err != nil { return nil, err diff --git a/cf/cf_test.go b/cf/cf_test.go index a5f0b7d..1d05a7e 100644 --- a/cf/cf_test.go +++ b/cf/cf_test.go @@ -43,6 +43,19 @@ func testCF(t *testing.T, when spec.G, it spec.S) { Expect(output).To(Equal(mockOutput)) }) + when("given a fully qualified path", func() { + it("makes it a relative URL", func() { + mockOutput, err := mocks.FileToString("apps.json") + Expect(err).NotTo(HaveOccurred()) + + mockConnection.EXPECT().CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/some-endpoint")).Return(mockOutput, nil).AnyTimes() + + output, err := c.CFCurl("https://api.example.com/v3/some-endpoint") + Expect(err).NotTo(HaveOccurred()) + Expect(output).To(Equal(mockOutput)) + }) + }) + when("hitting a V3 endpoint and CAPI returns an error JSON", func() { it("returns the error details in an error", func() { mockOutput, err := mocks.FileToString("errorV3.json") From 4dc83b31b6279c05f2182fa640a70bb6d4944a7e Mon Sep 17 00:00:00 2001 From: Al Berez Date: Wed, 13 Nov 2024 07:26:33 -0800 Subject: [PATCH 2/2] Fix syntax --- cf/cf_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cf/cf_test.go b/cf/cf_test.go index bbc4352..95635ae 100644 --- a/cf/cf_test.go +++ b/cf/cf_test.go @@ -36,8 +36,8 @@ var _ = Describe("CF", func() { Expect(output).To(Equal(mockOutput)) }) - when("given a fully qualified path", func() { - it("makes it a relative URL", func() { + When("given a fully qualified path", func() { + It("makes it a relative URL", func() { mockOutput, err := mocks.FileToString("apps.json") Expect(err).NotTo(HaveOccurred()) @@ -49,8 +49,8 @@ var _ = Describe("CF", func() { }) }) - when("hitting a V3 endpoint and CAPI returns an error JSON", func() { - it("returns the error details in an error", func() { + When("hitting a V3 endpoint and CAPI returns an error JSON", func() { + It("returns the error details in an error", func() { mockOutput, err := mocks.FileToString("errorV3.json") Expect(err).NotTo(HaveOccurred())