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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### Bug Fixes:

- fix(json): `secret-store list --json` emits `[]` rather than `null` on an account with no secret stores

### Enhancements:

### Dependencies:
Expand Down
5 changes: 4 additions & 1 deletion pkg/commands/secretstore/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ func (c *ListCommand) Exec(in io.Reader, out io.Writer) error {
return fsterr.ErrInvalidVerboseJSONCombo
}

var data []fastly.SecretStore
// Initialised rather than declared nil so that an account with no secret
// stores encodes as `[]` instead of `null`: encoding/json writes a nil
// slice as null, and `--json` output should be a list either way.
data := make([]fastly.SecretStore, 0)

for {
o, err := c.Globals.APIClient.ListSecretStores(context.TODO(), &c.Input)
Expand Down
24 changes: 24 additions & 0 deletions pkg/commands/secretstore/secretstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,30 @@ func TestListStoresCommand(t *testing.T) {
wantAPIInvoked: true,
wantOutput: fstfmt.EncodeJSON([]fastly.SecretStore{stores.Data[0]}),
},
// An account with no secret stores used to print `null` here while
// `config-store list --json` printed `[]` for the same situation.
{
args: "list --json",
api: mock.API{
ListSecretStoresFn: func(_ context.Context, _ *fastly.ListSecretStoresInput) (*fastly.SecretStores, error) {
return &fastly.SecretStores{Data: []fastly.SecretStore{}}, nil
},
},
wantAPIInvoked: true,
wantOutput: "[]\n",
},
// The same, reached by the other route: the API returned no response
// body at all, so nothing was ever appended.
{
args: "list --json",
api: mock.API{
ListSecretStoresFn: func(_ context.Context, _ *fastly.ListSecretStoresInput) (*fastly.SecretStores, error) {
return nil, nil
},
},
wantAPIInvoked: true,
wantOutput: "[]\n",
},
}

for _, testcase := range scenarios {
Expand Down