Skip to content

Commit 6dd4e61

Browse files
author
Jan Sternagel
committed
Added the 'nil response' test case for the outputResult()
1 parent 2f68ead commit 6dd4e61

File tree

13 files changed

+67
-2
lines changed

13 files changed

+67
-2
lines changed

internal/cmd/beta/kms/key/delete/delete_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,11 @@ func TestOutputResult(t *testing.T) {
255255
outputFormat string
256256
resp *kms.Key
257257
}{
258+
{
259+
description: "nil response",
260+
resp: nil,
261+
wantErr: true,
262+
},
258263
{
259264
description: "default output",
260265
resp: &kms.Key{},

internal/cmd/beta/kms/key/list/list.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ func configureFlags(cmd *cobra.Command) {
106106
}
107107

108108
func outputResult(p *print.Printer, outputFormat, projectId, keyRingId string, keys []kms.Key) error {
109+
if keys == nil {
110+
return fmt.Errorf("response was an empty list")
111+
}
112+
109113
switch outputFormat {
110114
case print.JSONOutputFormat:
111115
details, err := json.MarshalIndent(keys, "", " ")

internal/cmd/beta/kms/key/list/list_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,13 @@ func TestOutputResult(t *testing.T) {
206206
outputFormat string
207207
wantErr bool
208208
}{
209-
// Response check was moved inside NewCmd() for better error feedback.
210-
// Thus, no check for 'keys = nil' needed
209+
{
210+
description: "nil response",
211+
keys: nil,
212+
projectId: uuid.NewString(),
213+
keyRingId: uuid.NewString(),
214+
wantErr: true,
215+
},
211216
{
212217
description: "default output",
213218
keys: []kms.Key{},

internal/cmd/beta/kms/key/restore/restore_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,11 @@ func TestOutputResult(t *testing.T) {
255255
outputFormat string
256256
resp *kms.Key
257257
}{
258+
{
259+
description: "nil response",
260+
resp: nil,
261+
wantErr: true,
262+
},
258263
{
259264
description: "default output",
260265
resp: &kms.Key{},

internal/cmd/beta/kms/keyring/delete/delete_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@ func TestOutputResult(t *testing.T) {
218218
outputFormat string
219219
resp *kms.KeyRing
220220
}{
221+
{
222+
description: "nil response",
223+
resp: nil,
224+
wantErr: true,
225+
},
221226
{
222227
description: "default output",
223228
resp: &kms.KeyRing{},

internal/cmd/beta/kms/keyring/list/list.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *kms.APIClie
9292
}
9393

9494
func outputResult(p *print.Printer, outputFormat, projectId string, keyRings []kms.KeyRing) error {
95+
if keyRings == nil {
96+
return fmt.Errorf("response was nil")
97+
}
98+
9599
switch outputFormat {
96100
case print.JSONOutputFormat:
97101
details, err := json.MarshalIndent(keyRings, "", " ")

internal/cmd/beta/kms/keyring/list/list_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,13 @@ func TestOutputResult(t *testing.T) {
179179
projectLabel string
180180
wantErr bool
181181
}{
182+
{
183+
description: "nil response",
184+
keyRings: nil,
185+
projectId: uuid.NewString(),
186+
projectLabel: "my-project",
187+
wantErr: true,
188+
},
182189
{
183190
description: "default output",
184191
projectId: uuid.NewString(),

internal/cmd/beta/kms/version/destroy/destroy_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@ func TestOutputResult(t *testing.T) {
283283
outputFormat string
284284
resp *kms.Version
285285
}{
286+
{
287+
description: "nil response",
288+
resp: nil,
289+
wantErr: true,
290+
},
286291
{
287292
description: "default output",
288293
resp: &kms.Version{},

internal/cmd/beta/kms/version/disable/disable_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@ func TestOutputResult(t *testing.T) {
283283
outputFormat string
284284
resp *kms.Version
285285
}{
286+
{
287+
description: "nil response",
288+
resp: nil,
289+
wantErr: true,
290+
},
286291
{
287292
description: "default output",
288293
resp: &kms.Version{},

internal/cmd/beta/kms/version/enable/enable_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@ func TestOutputResult(t *testing.T) {
283283
outputFormat string
284284
resp *kms.Version
285285
}{
286+
{
287+
description: "nil response",
288+
resp: nil,
289+
wantErr: true,
290+
},
286291
{
287292
description: "default output",
288293
resp: &kms.Version{},

0 commit comments

Comments
 (0)