@@ -24,6 +24,7 @@ import (
2424 "github.com/slackapi/slack-cli/internal/iostreams"
2525 "github.com/slackapi/slack-cli/internal/shared"
2626 "github.com/slackapi/slack-cli/internal/slackcontext"
27+ "github.com/slackapi/slack-cli/internal/slackerror"
2728 "github.com/slackapi/slack-cli/test/testutil"
2829 "github.com/spf13/cobra"
2930 "github.com/stretchr/testify/assert"
@@ -81,21 +82,43 @@ func TestRootCommand(t *testing.T) {
8182
8283func TestExecuteContext (t * testing.T ) {
8384 tests := map [string ]struct {
84- expectedErr error
85- expectedExitCode iostreams.ExitCode
86- expectedOutputs []string
85+ mockErr error
86+ mockRuntime string
87+ expectedExitCode iostreams.ExitCode
88+ expectedOutputs []string
89+ unexpectedOutputs []string
8790 }{
8891 "Command successfully executes" : {
89- expectedErr : nil ,
92+ mockErr : nil ,
9093 expectedExitCode : iostreams .ExitOK ,
9194 },
9295 "Command fails execution and returns an error" : {
93- expectedErr : fmt .Errorf ("command failed" ),
96+ mockErr : fmt .Errorf ("command failed" ),
9497 expectedExitCode : iostreams .ExitError ,
9598 expectedOutputs : []string {
9699 "command failed" ,
97100 },
98101 },
102+ "Command fails execution with a missing hook and missing runtime" : {
103+ mockErr : slackerror .New (slackerror .ErrSDKHookNotFound ),
104+ expectedExitCode : iostreams .ExitError ,
105+ expectedOutputs : []string {
106+ slackerror .New (slackerror .ErrRuntimeNotFound ).
107+ WithRootCause (slackerror .New (slackerror .ErrSDKHookNotFound ).WithRemediation ("" )).
108+ Error (),
109+ },
110+ },
111+ "Command fails execution with a missing hook and existing runtime" : {
112+ mockErr : slackerror .New (slackerror .ErrSDKHookNotFound ),
113+ mockRuntime : "sh" ,
114+ expectedExitCode : iostreams .ExitError ,
115+ expectedOutputs : []string {
116+ slackerror .New (slackerror .ErrSDKHookNotFound ).Error (),
117+ },
118+ unexpectedOutputs : []string {
119+ slackerror .ErrRuntimeNotFound ,
120+ },
121+ },
99122 }
100123 for name , tt := range tests {
101124 t .Run (name , func (t * testing.T ) {
@@ -105,15 +128,18 @@ func TestExecuteContext(t *testing.T) {
105128 clientsMock := shared .NewClientsMock ()
106129 clientsMock .AddDefaultMocks ()
107130 clientsMock .EventTracker .On ("FlushToLogstash" , mock .Anything , mock .Anything , mock .Anything , mock .Anything ).Return (nil )
108- clients := shared .NewClientFactory (clientsMock .MockClientFactory ())
131+ clients := shared .NewClientFactory (clientsMock .MockClientFactory (), func (clients * shared.ClientFactory ) {
132+ clients .SDKConfig .Runtime = tt .mockRuntime
133+ })
109134
110135 // Mock command
111136 cmd := & cobra.Command {
112137 Use : "mock [flags]" ,
113138 RunE : func (cmd * cobra.Command , args []string ) error {
114- return tt .expectedErr
139+ return tt .mockErr
115140 },
116141 }
142+ testutil .MockCmdIO (clientsMock .IO , cmd )
117143
118144 // Execute the command
119145 ExecuteContext (ctx , cmd , clients )
@@ -126,6 +152,9 @@ func TestExecuteContext(t *testing.T) {
126152 for _ , expectedOutput := range tt .expectedOutputs {
127153 require .Contains (t , output , expectedOutput )
128154 }
155+ for _ , unexpectedOutputs := range tt .unexpectedOutputs {
156+ require .NotContains (t , output , unexpectedOutputs )
157+ }
129158 })
130159 }
131160}
0 commit comments