Skip to content

Commit 0c37e84

Browse files
committed
add testcase
1 parent c1a9ca7 commit 0c37e84

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

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

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

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

9+
"github.com/stackitcloud/stackit-cli/internal/pkg/config"
610
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
11+
"github.com/stackitcloud/stackit-cli/internal/pkg/testparams"
712
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
13+
"github.com/zalando/go-keyring"
814
)
915

1016
const testProfile = "test-profile"
@@ -81,3 +87,34 @@ func TestParseInput(t *testing.T) {
8187
})
8288
}
8389
}
90+
91+
// regression test for STACKITCLI-389
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)