diff --git a/cmd/platform/deploy.go b/cmd/platform/deploy.go index ec8fb97f..f11d85c3 100644 --- a/cmd/platform/deploy.go +++ b/cmd/platform/deploy.go @@ -316,16 +316,13 @@ func printDeployHostingCompletion(clients *shared.ClientFactory, cmd *cobra.Comm func errorMissingDeployHook(clients *shared.ClientFactory) error { if !clients.SDKConfig.Hooks.Deploy.IsAvailable() { return slackerror.New(slackerror.ErrSDKHookNotFound). - WithMessage("Missing the `deploy` hook from the `%s` file", config.GetProjectHooksJSONFilePath()). + WithMessage("No deploy script found"). WithRemediation("%s", strings.Join([]string{ - "Provide a command or script to run with the deploy command by adding a new hook.", + "For deployment options, see:", + " https://docs.slack.dev/tools/slack-cli/reference/hooks/#deploy", "", - fmt.Sprintf("Example `%s` `deploy` hook:", config.GetProjectHooksJSONFilePath()), - "{", - ` "hooks": {`, - ` "deploy": "./deploy.sh"`, - " }", - "}", + "To start a local development server, use:", + fmt.Sprintf(" %s", style.Commandf("run", false)), }, "\n")) } return nil diff --git a/cmd/platform/deploy_test.go b/cmd/platform/deploy_test.go index 5dc5c71a..7a8d1cff 100644 --- a/cmd/platform/deploy_test.go +++ b/cmd/platform/deploy_test.go @@ -111,12 +111,14 @@ func TestDeployCommand(t *testing.T) { func TestDeployCommand_HasValidDeploymentMethod(t *testing.T) { tests := map[string]struct { - app types.App - manifest types.SlackYaml - manifestError error - manifestSource config.ManifestSource - deployScript string - expectedError error + app types.App + manifest types.SlackYaml + manifestError error + manifestSource config.ManifestSource + deployScript string + expectedError error + expectedMessage string + expectedRemediation []string }{ "fails when no manifest exists": { manifestError: slackerror.New(slackerror.ErrInvalidManifest), @@ -142,8 +144,10 @@ func TestDeployCommand_HasValidDeploymentMethod(t *testing.T) { deployScript: "sleep 4", }, "fails if no deploy hook is provided": { - manifestSource: config.ManifestSourceLocal, - expectedError: slackerror.New(slackerror.ErrSDKHookNotFound), + manifestSource: config.ManifestSourceLocal, + expectedError: slackerror.New(slackerror.ErrSDKHookNotFound), + expectedMessage: "No deploy script found", + expectedRemediation: []string{"https://docs.slack.dev/tools/slack-cli/reference/hooks/#deploy", "run"}, }, "succeeds if the app exists and the manifest source is remote": { app: types.App{ @@ -183,11 +187,14 @@ func TestDeployCommand_HasValidDeploymentMethod(t *testing.T) { err := hasValidDeploymentMethod(ctx, clients, app, types.SlackAuth{}) if tc.expectedError != nil { require.Error(t, err) - assert.Equal( - t, - slackerror.ToSlackError(tc.expectedError).Code, - slackerror.ToSlackError(err).Code, - ) + slackErr := slackerror.ToSlackError(err) + assert.Equal(t, slackerror.ToSlackError(tc.expectedError).Code, slackErr.Code) + if tc.expectedMessage != "" { + assert.Contains(t, slackErr.Message, tc.expectedMessage) + } + for _, r := range tc.expectedRemediation { + assert.Contains(t, slackErr.Remediation, r) + } } else { require.NoError(t, err) } @@ -197,10 +204,13 @@ func TestDeployCommand_HasValidDeploymentMethod(t *testing.T) { func TestDeployCommand_DeployHook(t *testing.T) { tests := map[string]struct { - command string - expectedStderr []string - expectedStdout string - expectedError error + command string + emptyDeployHook bool + expectedStderr []string + expectedStdout string + expectedError error + expectedMessage string + expectedRemediation string }{ "fails to execute an unknown script path": { command: "./deployer.sh", @@ -257,7 +267,11 @@ func TestDeployCommand_DeployHook(t *testing.T) { clientsMock.AddDefaultMocks() sdkConfigMock := hooks.NewSDKConfigMock() sdkConfigMock.Config.SupportedProtocols = []hooks.Protocol{hooks.HookProtocolDefault} - sdkConfigMock.Hooks.Deploy = hooks.HookScript{Name: "Deploy", Command: tc.command} + if tc.emptyDeployHook { + sdkConfigMock.Hooks.Deploy = hooks.HookScript{} + } else { + sdkConfigMock.Hooks.Deploy = hooks.HookScript{Name: "Deploy", Command: tc.command} + } stdoutLogger := log.Logger{} stdoutBuffer := bytes.Buffer{} @@ -281,6 +295,15 @@ func TestDeployCommand_DeployHook(t *testing.T) { cmd.PreRunE = func(cmd *cobra.Command, args []string) error { return nil } testutil.MockCmdIO(clients.IO, cmd) + if tc.emptyDeployHook { + err := errorMissingDeployHook(clients) + require.Error(t, err) + slackErr := slackerror.ToSlackError(err) + assert.Equal(t, tc.expectedError.(*slackerror.Error).Code, slackErr.Code) + assert.Contains(t, slackErr.Message, tc.expectedMessage) + assert.Contains(t, slackErr.Remediation, tc.expectedRemediation) + return + } err := cmd.ExecuteContext(ctx) assert.Contains(t, stdoutBuffer.String(), tc.command) if tc.expectedError != nil {