Skip to content
13 changes: 5 additions & 8 deletions cmd/platform/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
59 changes: 41 additions & 18 deletions cmd/platform/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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{
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
Comment on lines +207 to +213
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
command string
emptyDeployHook bool
expectedStderr []string
expectedStdout string
expectedError error
expectedMessage string
expectedRemediation string
command string
expectedStderr []string
expectedStdout string
expectedError error

🔮 question: Can we revert these changes too?

}{
"fails to execute an unknown script path": {
command: "./deployer.sh",
Expand Down Expand Up @@ -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}
}
Comment on lines +270 to +274
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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{}
Expand All @@ -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
}
Comment on lines +298 to +306
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 {
Expand Down
Loading