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
8 changes: 7 additions & 1 deletion cf/cf.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ func (cf *CF) getAllSpaces() (resources.Spaces, error) {
}

var spaces resources.SpacesJSON
if strings.Join(spacesJSON, "") == "" {
Comment thread
nookala marked this conversation as resolved.
break
}
if err := json.Unmarshal([]byte(strings.Join(spacesJSON, "")), &spaces); err != nil {
return nil, fmt.Errorf("error unmarshaling spaces json: %v", err)
}
Expand All @@ -146,9 +149,12 @@ func (cf *CF) GetAllApps() ([]resources.V3AppsJSON, error) {
}

var apps resources.V3AppsJSON
if strings.Join(appJSON, "") == "" {
break
}

if err := json.Unmarshal([]byte(strings.Join(appJSON, "")), &apps); err != nil {
return nil, fmt.Errorf("error unmarshaling apps json: %v", err)
return nil, fmt.Errorf("error unmarshaling apps json: %v", appJSON)
}
nextURL = apps.Pagination.Next.Href
allApps = append(allApps, apps)
Expand Down
13 changes: 13 additions & 0 deletions cf/cf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/cloudfoundry/stack-auditor/cf"

"github.com/cloudfoundry/stack-auditor/mocks"
"github.com/cloudfoundry/stack-auditor/resources"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -24,6 +25,18 @@ var _ = Describe("CF", func() {
c = cf.CF{Conn: mockConnection}
})

When("getAllApps", func() {
It("performs a successful getAllApps with empty Json", func() {
mockOutput := make([]string, 3)
var allApps []resources.V3AppsJSON
cf.V3ResultsPerPage = "1"
mockConnection.EXPECT().CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/apps?per_page=1")).Return(mockOutput, nil).AnyTimes()
output, err := c.GetAllApps()
Expect(err).NotTo(HaveOccurred())
Expect(output).To(Equal(allApps))
})
})

When("CFCurl", func() {
It("performs a successful CF curl", func() {
mockOutput, err := mocks.FileToString("apps.json")
Expand Down