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
8 changes: 4 additions & 4 deletions internal/cmd/config/profile/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
37 changes: 37 additions & 0 deletions internal/cmd/config/profile/delete/delete_test.go
Original file line number Diff line number Diff line change
@@ -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"
)

Expand Down Expand Up @@ -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)
}
}
Loading