diff --git a/cli/azd/internal/repository/initializer.go b/cli/azd/internal/repository/initializer.go index 9fe2499ca65..5a4f64945b7 100644 --- a/cli/azd/internal/repository/initializer.go +++ b/cli/azd/internal/repository/initializer.go @@ -583,7 +583,9 @@ func (i *Initializer) PromptIfNonEmpty(ctx context.Context, azdCtx *azdcontext.A } if !confirm { - return fmt.Errorf("confirmation declined") + successMessage := "\n\nconfirmation declined; app was not initialized" + i.console.Message(ctx, successMessage) + os.Exit(1) } } diff --git a/cli/azd/internal/repository/initializer_test.go b/cli/azd/internal/repository/initializer_test.go index 0b951ed8c40..dbe8fd0ee5e 100644 --- a/cli/azd/internal/repository/initializer_test.go +++ b/cli/azd/internal/repository/initializer_test.go @@ -574,10 +574,10 @@ func TestInitializer_PromptIfNonEmpty(t *testing.T) { files []string } tests := []struct { - name string - dir dirSetup - userConfirm bool - expectedErr string + name string + dir dirSetup + userConfirm bool + declinedOutput string }{ { "EmptyDir", @@ -595,7 +595,7 @@ func TestInitializer_PromptIfNonEmpty(t *testing.T) { "NonEmptyDir_Declined", dirSetup{false, []string{"a.txt"}}, false, - "confirmation declined", + "confirmation declined; app was not initialized", }, { "NonEmptyGitDir", @@ -607,7 +607,7 @@ func TestInitializer_PromptIfNonEmpty(t *testing.T) { "NonEmptyGitDir_Declined", dirSetup{true, []string{"a.txt"}}, false, - "confirmation declined", + "confirmation declined; app was not initialized", }, } for _, tt := range tests { @@ -642,12 +642,12 @@ func TestInitializer_PromptIfNonEmpty(t *testing.T) { gitCli: gitCli, } azdCtx := azdcontext.NewAzdContextWithDirectory(dir) - err := i.PromptIfNonEmpty(context.Background(), azdCtx) - if tt.expectedErr != "" { - require.Error(t, err) - assert.Contains(t, err.Error(), tt.expectedErr) - } else { + // we only test if declinedOutput is empty + // if confirmation is declined and app is not initialized + // we skip the test as it will exit with code 1 + if tt.declinedOutput == "" { + err := i.PromptIfNonEmpty(context.Background(), azdCtx) require.NoError(t, err) } })