diff --git a/internal/cmd/config/profile/delete/delete.go b/internal/cmd/config/profile/delete/delete.go index a81bf7888..d94f71479 100644 --- a/internal/cmd/config/profile/delete/delete.go +++ b/internal/cmd/config/profile/delete/delete.go @@ -71,14 +71,14 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - err = config.DeleteProfile(params.Printer, model.Profile) + err = auth.DeleteProfileAuth(model.Profile) if err != nil { - return fmt.Errorf("delete profile: %w", err) + return fmt.Errorf("delete profile authentication: %w", err) } - err = auth.DeleteProfileAuth(model.Profile) + err = config.DeleteProfile(params.Printer, model.Profile) if err != nil { - return fmt.Errorf("delete profile authentication: %w", err) + return fmt.Errorf("delete profile: %w", err) } params.Printer.Info("Successfully deleted profile %q\n", model.Profile) diff --git a/internal/cmd/config/profile/delete/delete_test.go b/internal/cmd/config/profile/delete/delete_test.go index 2ca839f58..919ddb078 100644 --- a/internal/cmd/config/profile/delete/delete_test.go +++ b/internal/cmd/config/profile/delete/delete_test.go @@ -1,9 +1,16 @@ package delete import ( + "fmt" + "os" "testing" + "time" + "github.com/zalando/go-keyring" + + "github.com/stackitcloud/stackit-cli/internal/pkg/config" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" "github.com/stackitcloud/stackit-cli/internal/pkg/testutils" ) @@ -81,3 +88,33 @@ func TestParseInput(t *testing.T) { }) } } + +func TestDeleteProfileWithoutKeyring(t *testing.T) { + params := testparams.NewTestParams() + params.Printer.AssumeYes = true + profile := fmt.Sprintf("test-profile-%s", time.Now().Format("20060102150405")) + path := config.GetProfileFolderPath(profile) + t.Cleanup(func() { + err := os.RemoveAll(path) + if err != nil { + t.Fatalf("cleanup: remove profile folder at path %q: %v", path, err) + } + }) + err := config.ValidateProfile(profile) + if err != nil { + t.Fatalf("validate profile %q: %v", profile, err) + } + err = config.CreateProfile(params.Printer, profile, true, false, true) + if err != nil { + t.Fatalf("create profile %q: %v", profile, err) + } + keyring.MockInitWithError(keyring.ErrUnsupportedPlatform) + deleteCmd := NewCmd(params.CmdParams) + err = deleteCmd.RunE(deleteCmd, []string{profile}) + if err != nil { + t.Fatalf("run cmd: %v", err) + } + if _, err := os.Stat(path); !os.IsNotExist(err) { + t.Fatalf("expected profile folder to be deleted, but it still exists at path %q", path) + } +}