55 "encoding/json"
66 "fmt"
77 "net/http"
8+ "strings"
89 "testing"
910
1011 "github.com/spf13/cobra"
@@ -243,6 +244,8 @@ func TestKeyBulkUpdate_InvalidJSON(t *testing.T) {
243244 err := rootCmd .Execute ()
244245 if err == nil {
245246 t .Error ("Expected error for invalid JSON, got nil" )
247+ } else if ! strings .Contains (err .Error (), "invalid character" ) {
248+ t .Errorf ("Expected JSON parse error, got: %v" , err )
246249 }
247250}
248251
@@ -259,6 +262,27 @@ func TestKeyBulkCreate_InvalidJSON(t *testing.T) {
259262 err := rootCmd .Execute ()
260263 if err == nil {
261264 t .Error ("Expected error for invalid JSON, got nil" )
265+ } else if ! strings .Contains (err .Error (), "invalid character" ) {
266+ t .Errorf ("Expected JSON parse error, got: %v" , err )
267+ }
268+ }
269+
270+ func TestKeyBulkDelete_EmptyKeyIds (t * testing.T ) {
271+ client , _ , _ , teardown := setup ()
272+ defer teardown ()
273+
274+ // Reset package-level var that may retain state from prior tests
275+ bulkDeleteKeyIds = []int64 {}
276+
277+ args := []string {"key" , "bulk-delete" , "--key-ids=" , "--project-id=" + testProjectID }
278+ rootCmd .SetArgs (args )
279+ keyBulkDeleteCmd .PreRun = func (cmd * cobra.Command , args []string ) {
280+ Api = client
281+ }
282+
283+ err := rootCmd .Execute ()
284+ if err == nil {
285+ t .Error ("Expected error for empty key-ids, got nil" )
262286 }
263287}
264288
@@ -275,6 +299,8 @@ func TestKeyBulkUpdate_EmptyKeys(t *testing.T) {
275299 err := rootCmd .Execute ()
276300 if err == nil {
277301 t .Error ("Expected error for empty keys, got nil" )
302+ } else if err .Error () != "--keys must contain at least one key object" {
303+ t .Errorf ("Expected empty keys error, got: %v" , err )
278304 }
279305}
280306
@@ -291,5 +317,8 @@ func TestKeyBulkCreate_EmptyKeys(t *testing.T) {
291317 err := rootCmd .Execute ()
292318 if err == nil {
293319 t .Error ("Expected error for empty keys, got nil" )
320+ } else if err .Error () != "--keys must contain at least one key object" {
321+ t .Errorf ("Expected empty keys error, got: %v" , err )
294322 }
295323}
324+
0 commit comments