Skip to content

Commit d6c7108

Browse files
authored
fix(config): fix deletion of profiles on some systems (#1389)
relates to STACKITCLI-389
1 parent 80963e0 commit d6c7108

2 files changed

Lines changed: 41 additions & 4 deletions

File tree

internal/cmd/config/profile/delete/delete.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
7171
return err
7272
}
7373

74-
err = config.DeleteProfile(params.Printer, model.Profile)
74+
err = auth.DeleteProfileAuth(model.Profile)
7575
if err != nil {
76-
return fmt.Errorf("delete profile: %w", err)
76+
return fmt.Errorf("delete profile authentication: %w", err)
7777
}
7878

79-
err = auth.DeleteProfileAuth(model.Profile)
79+
err = config.DeleteProfile(params.Printer, model.Profile)
8080
if err != nil {
81-
return fmt.Errorf("delete profile authentication: %w", err)
81+
return fmt.Errorf("delete profile: %w", err)
8282
}
8383

8484
params.Printer.Info("Successfully deleted profile %q\n", model.Profile)

internal/cmd/config/profile/delete/delete_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
package delete
22

33
import (
4+
"fmt"
5+
"os"
46
"testing"
7+
"time"
58

9+
"github.com/zalando/go-keyring"
10+
11+
"github.com/stackitcloud/stackit-cli/internal/pkg/config"
612
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
13+
"github.com/stackitcloud/stackit-cli/internal/pkg/testparams"
714
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
815
)
916

@@ -81,3 +88,33 @@ func TestParseInput(t *testing.T) {
8188
})
8289
}
8390
}
91+
92+
func TestDeleteProfileWithoutKeyring(t *testing.T) {
93+
params := testparams.NewTestParams()
94+
params.Printer.AssumeYes = true
95+
profile := fmt.Sprintf("test-profile-%s", time.Now().Format("20060102150405"))
96+
path := config.GetProfileFolderPath(profile)
97+
t.Cleanup(func() {
98+
err := os.RemoveAll(path)
99+
if err != nil {
100+
t.Fatalf("cleanup: remove profile folder at path %q: %v", path, err)
101+
}
102+
})
103+
err := config.ValidateProfile(profile)
104+
if err != nil {
105+
t.Fatalf("validate profile %q: %v", profile, err)
106+
}
107+
err = config.CreateProfile(params.Printer, profile, true, false, true)
108+
if err != nil {
109+
t.Fatalf("create profile %q: %v", profile, err)
110+
}
111+
keyring.MockInitWithError(keyring.ErrUnsupportedPlatform)
112+
deleteCmd := NewCmd(params.CmdParams)
113+
err = deleteCmd.RunE(deleteCmd, []string{profile})
114+
if err != nil {
115+
t.Fatalf("run cmd: %v", err)
116+
}
117+
if _, err := os.Stat(path); !os.IsNotExist(err) {
118+
t.Fatalf("expected profile folder to be deleted, but it still exists at path %q", path)
119+
}
120+
}

0 commit comments

Comments
 (0)