WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
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
17 changes: 15 additions & 2 deletions command/v7/service_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v7

import (
"fmt"
"sort"
"strconv"

"code.cloudfoundry.org/cli/v8/actor/v7action"
Expand Down Expand Up @@ -240,13 +241,25 @@ func (cmd ServiceCommand) displayBoundApps(serviceInstanceWithDetails v7action.S
return
}

table := [][]string{{"name", "binding name", "status", "message"}}
for _, app := range serviceInstanceWithDetails.BoundApps {
table := [][]string{{"name", "binding name", "status", "message", "guid", "created_at"}}

bindings := serviceInstanceWithDetails.BoundApps
// sort by app name, then by created at descending
sort.Slice(bindings, func(i, j int) bool {
if bindings[i].AppName == bindings[j].AppName {
return bindings[i].CreatedAt > bindings[j].CreatedAt
}
return bindings[i].AppName < bindings[j].AppName
})

for _, app := range bindings {
table = append(table, []string{
app.AppName,
app.Name,
fmt.Sprintf("%s %s", app.LastOperation.Type, app.LastOperation.State),
app.LastOperation.Description,
app.GUID,
app.CreatedAt,
})
}

Expand Down
32 changes: 26 additions & 6 deletions command/v7/service_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,19 +271,23 @@ var _ = Describe("service command", func() {
{
Name: "named-binding",
AppName: "app-1",
GUID: "guid-1",
LastOperation: resources.LastOperation{
Type: resources.CreateOperation,
State: resources.OperationSucceeded,
Description: "great",
},
CreatedAt: "created-at-1",
},
{
AppName: "app-2",
GUID: "guid-2",
LastOperation: resources.LastOperation{
Type: resources.UpdateOperation,
State: resources.OperationFailed,
Description: "sorry",
},
CreatedAt: "created-at-2",
},
},
},
Expand All @@ -295,9 +299,9 @@ var _ = Describe("service command", func() {
It("prints the bound apps table", func() {
Expect(testUI.Out).To(SatisfyAll(
Say(`Showing bound apps:\n`),
Say(` name\s+binding name\s+status\s+message\n`),
Say(` app-1\s+named-binding\s+create succeeded\s+great\n`),
Say(` app-2\s+update failed\s+sorry\n`),
Say(` name\s+binding name\s+status\s+message\s+guid\s+created_at\n`),
Say(` app-1\s+named-binding\s+create succeeded\s+great\s+guid-1\s+created-at-1\n`),
Say(` app-2\s+update failed\s+sorry\s+guid-2\s+created-at-2\n`),
))
})
})
Expand Down Expand Up @@ -704,19 +708,34 @@ var _ = Describe("service command", func() {
{
Name: "named-binding",
AppName: "app-1",
GUID: "guid-1",
LastOperation: resources.LastOperation{
Type: resources.CreateOperation,
State: resources.OperationSucceeded,
Description: "great",
},
CreatedAt: "created-at-1",
},
{
AppName: "app-2",
GUID: "guid-2",
LastOperation: resources.LastOperation{
Type: resources.UpdateOperation,
State: resources.OperationFailed,
Description: "sorry",
},
CreatedAt: "created-at-2",
},
{
Name: "named-binding",
AppName: "app-1",
GUID: "guid-3",
LastOperation: resources.LastOperation{
Type: resources.CreateOperation,
State: resources.OperationSucceeded,
Description: "great",
},
CreatedAt: "created-at-2",
},
},
},
Expand All @@ -728,9 +747,10 @@ var _ = Describe("service command", func() {
It("prints the bound apps table", func() {
Expect(testUI.Out).To(SatisfyAll(
Say(`Showing bound apps:\n`),
Say(`name\s+binding name\s+status\s+message\n`),
Say(`app-1\s+named-binding\s+create succeeded\s+great\n`),
Say(`app-2\s+update failed\s+sorry\n`),
Say(`name\s+binding name\s+status\s+message\s+guid\s+created_at\n`),
Say(`app-1\s+named-binding\s+create succeeded\s+great\s+guid-3\s+created-at-2\n`),
Say(`app-1\s+named-binding\s+create succeeded\s+great\s+guid-1\s+created-at-1\n`),
Say(`app-2\s+update failed\s+sorry\s+guid-2\s+created-at-2\n`),
))
})
})
Expand Down
12 changes: 6 additions & 6 deletions integration/v7/isolated/service_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ var _ = Describe("service command", func() {

Expect(session).To(SatisfyAll(
Say(`Showing bound apps:\n`),
Say(`name\s+binding name\s+status\s+message\n`),
Say(`%s\s+%s\s+create succeeded\s*\n`, appName1, bindingName1),
Say(`%s\s+%s\s+create succeeded\s*\n`, appName2, bindingName2),
Say(`name\s+binding name\s+status\s+message\s+guid\s+created_at\n`),
Say(`%s\s+%s\s+create succeeded\s+%s\s+%s\n`, appName1, bindingName1, helpers.GUIDRegex, helpers.TimestampRegex),
Say(`%s\s+%s\s+create succeeded\s+%s\s+%s\n`, appName2, bindingName2, helpers.GUIDRegex, helpers.TimestampRegex),
))
})
})
Expand Down Expand Up @@ -528,9 +528,9 @@ var _ = Describe("service command", func() {

Expect(session).To(SatisfyAll(
Say(`Showing bound apps:\n`),
Say(`name\s+binding name\s+status\s+message\n`),
Say(`%s\s+%s\s+create succeeded\s+very happy service\n`, appName1, bindingName1),
Say(`%s\s+%s\s+create succeeded\s+very happy service\n`, appName2, bindingName2),
Say(`name\s+binding name\s+status\s+message\s+guid\s+created_at\n`),
Say(`%s\s+%s\s+create succeeded\s+very happy service\s+%s\s+%s\n`, appName1, bindingName1, helpers.GUIDRegex, helpers.TimestampRegex),
Say(`%s\s+%s\s+create succeeded\s+very happy service\s+%s\s+%s\n`, appName2, bindingName2, helpers.GUIDRegex, helpers.TimestampRegex),
))
})
})
Expand Down
2 changes: 2 additions & 0 deletions resources/service_credential_binding_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type ServiceCredentialBinding struct {
LastOperation LastOperation `jsonry:"last_operation"`
// Parameters can be specified when creating a binding
Parameters types.OptionalObject `jsonry:"parameters"`
// CreatedAt timestamp when the binding was created (useful for distinguishing multiple bindings)
CreatedAt string `json:"created_at,omitempty"`
}

func (s ServiceCredentialBinding) MarshalJSON() ([]byte, error) {
Expand Down
5 changes: 4 additions & 1 deletion resources/service_credential_binding_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ var _ = Describe("service credential binding resource", func() {
}
}`,
),
Entry("created_at", ServiceCredentialBinding{CreatedAt: "fake-created-at"}, `{"created_at": "fake-created-at"}`),
Entry(
"everything",
ServiceCredentialBinding{
Expand All @@ -71,6 +72,7 @@ var _ = Describe("service credential binding resource", func() {
Parameters: types.NewOptionalObject(map[string]interface{}{
"foo": "bar",
}),
CreatedAt: "fake-created-at",
},
`{
"type": "app",
Expand All @@ -90,7 +92,8 @@ var _ = Describe("service credential binding resource", func() {
},
"parameters": {
"foo": "bar"
}
},
"created_at": "fake-created-at"
}`,
),
)
Expand Down
Loading