Skip to content

Commit ae827f7

Browse files
Alexandre CatalanAlexandre Catalan
authored andcommitted
feat(container-registry): display recovery warning on artifactory delete
Display a warning informing users that STACKIT Container Registry projects can be recovered via a support request for up to 30 days after deletion. Remove the contradictory '(This cannot be undone)' suffix from the confirmation prompt and add unit test coverage for the warning output. Relates to STACKITCRE-382
1 parent 4ac21cd commit ae827f7

2 files changed

Lines changed: 61 additions & 1 deletion

File tree

‎internal/cmd/container-registry/artifactory/delete/delete.go‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
const (
2424
artifactoryIdArg = "ARTIFACTORY_ID"
25+
warningMessage = "Your STACKIT Container Registry projects are recoverable for up to 30 days after deletion via a support request. After this period, projects and their data are permanently unrecoverable."
2526
)
2627

2728
type inputModel struct {
@@ -59,7 +60,9 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
5960
artifactoryLabel = model.ArtifactoryId
6061
}
6162

62-
prompt := fmt.Sprintf("Are you sure you want to delete artifactory %q? (This cannot be undone)", artifactoryLabel)
63+
printWarning(params.Printer)
64+
65+
prompt := fmt.Sprintf("Are you sure you want to delete artifactory %q?", artifactoryLabel)
6366
err = params.Printer.PromptForConfirmation(prompt)
6467
if err != nil {
6568
return err
@@ -114,3 +117,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
114117
func buildRequest(ctx context.Context, model *inputModel, apiClient *registry.APIClient) registry.ApiDeleteArtifactoryRequest {
115118
return apiClient.DefaultAPI.DeleteArtifactory(ctx, model.ProjectId, model.Region, model.ArtifactoryId)
116119
}
120+
121+
func printWarning(p *print.Printer) {
122+
p.Warn("%s\n", warningMessage)
123+
}

‎internal/cmd/container-registry/artifactory/delete/delete_test.go‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package delete
22

33
import (
44
"context"
5+
"strings"
56
"testing"
67

78
"github.com/google/go-cmp/cmp"
@@ -10,6 +11,8 @@ import (
1011
registry "github.com/stackitcloud/stackit-sdk-go/services/registry/v1api"
1112

1213
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
14+
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
15+
"github.com/stackitcloud/stackit-cli/internal/pkg/testparams"
1316
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
1417
)
1518

@@ -166,3 +169,53 @@ func TestBuildRequest(t *testing.T) {
166169
})
167170
}
168171
}
172+
173+
func TestPrintWarning(t *testing.T) {
174+
tests := []struct {
175+
name string
176+
verbosity print.Level
177+
expectWarn bool
178+
}{
179+
{
180+
name: "default verbosity (info)",
181+
verbosity: print.InfoLevel,
182+
expectWarn: true,
183+
},
184+
{
185+
name: "warning verbosity",
186+
verbosity: print.WarningLevel,
187+
expectWarn: true,
188+
},
189+
{
190+
name: "debug verbosity",
191+
verbosity: print.DebugLevel,
192+
expectWarn: true,
193+
},
194+
{
195+
name: "error verbosity",
196+
verbosity: print.ErrorLevel,
197+
expectWarn: false,
198+
},
199+
}
200+
201+
for _, tt := range tests {
202+
t.Run(tt.name, func(t *testing.T) {
203+
params := testparams.NewTestParams()
204+
params.Printer.Verbosity = tt.verbosity
205+
206+
printWarning(params.Printer)
207+
208+
warned := strings.Contains(params.Err.String(), warningMessage)
209+
if warned != tt.expectWarn {
210+
t.Errorf("expected warning = %t, got %t (stderr: %q)", tt.expectWarn, warned, params.Err.String())
211+
}
212+
})
213+
}
214+
}
215+
216+
func TestWarningMessageContent(t *testing.T) {
217+
expected := "Your STACKIT Container Registry projects are recoverable for up to 30 days after deletion via a support request. After this period, projects and their data are permanently unrecoverable."
218+
if warningMessage != expected {
219+
t.Errorf("warning message mismatch:\ngot: %q\nwant: %q", warningMessage, expected)
220+
}
221+
}

0 commit comments

Comments
 (0)