Skip to content

Commit 689378a

Browse files
committed
Fail API key delete when key is missing
1 parent a40ea55 commit 689378a

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

cmd/api_keys.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,7 @@ func (c APIKeysCmd) Delete(ctx context.Context, in APIKeysDeleteInput) error {
192192

193193
if err := c.apiKeys.Delete(ctx, in.ID); err != nil {
194194
if util.IsNotFound(err) {
195-
pterm.Info.Printf("API key '%s' not found\n", in.ID)
196-
return nil
195+
return fmt.Errorf("API key %q not found", in.ID)
197196
}
198197
return util.CleanedUpSdkError{Err: err}
199198
}

cmd/api_keys_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"errors"
7+
"net/http"
78
"testing"
89

910
"github.com/kernel/kernel-go-sdk"
@@ -240,6 +241,20 @@ func TestAPIKeysDeleteSkipsConfirmation(t *testing.T) {
240241
assert.Contains(t, buf.String(), "Deleted API key: key_123")
241242
}
242243

244+
func TestAPIKeysDeleteReturnsNotFoundError(t *testing.T) {
245+
fake := &FakeAPIKeysService{
246+
DeleteFunc: func(ctx context.Context, id string, opts ...option.RequestOption) error {
247+
assert.Equal(t, "missing_key", id)
248+
return &kernel.Error{StatusCode: http.StatusNotFound}
249+
},
250+
}
251+
c := APIKeysCmd{apiKeys: fake}
252+
253+
err := c.Delete(context.Background(), APIKeysDeleteInput{ID: "missing_key", SkipConfirm: true})
254+
require.Error(t, err)
255+
assert.Contains(t, err.Error(), `API key "missing_key" not found`)
256+
}
257+
243258
func TestAPIKeysDeleteReturnsAPIError(t *testing.T) {
244259
fake := &FakeAPIKeysService{
245260
DeleteFunc: func(ctx context.Context, id string, opts ...option.RequestOption) error {

0 commit comments

Comments
 (0)