Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions cf/cf.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,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
Expand Down
13 changes: 13 additions & 0 deletions cf/cf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ var _ = Describe("CF", func() {
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")
Expand Down