|
1 | 1 | package delete |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "fmt" |
| 5 | + "os" |
4 | 6 | "testing" |
| 7 | + "time" |
5 | 8 |
|
| 9 | + "github.com/zalando/go-keyring" |
| 10 | + |
| 11 | + "github.com/stackitcloud/stackit-cli/internal/pkg/config" |
6 | 12 | "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" |
| 13 | + "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" |
7 | 14 | "github.com/stackitcloud/stackit-cli/internal/pkg/testutils" |
8 | 15 | ) |
9 | 16 |
|
@@ -81,3 +88,33 @@ func TestParseInput(t *testing.T) { |
81 | 88 | }) |
82 | 89 | } |
83 | 90 | } |
| 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