@@ -25,6 +25,7 @@ import (
2525 "github.com/slackapi/slack-cli/internal/slackcontext"
2626 "github.com/slackapi/slack-cli/internal/slackdeps"
2727 "github.com/slackapi/slack-cli/internal/slackerror"
28+ "github.com/spf13/afero"
2829 "github.com/stretchr/testify/assert"
2930 "github.com/stretchr/testify/require"
3031)
@@ -41,6 +42,7 @@ func mockBoundaryStringGenerator() string {
4142func Test_Hook_Execute_V2_Protocol (t * testing.T ) {
4243 tests := map [string ]struct {
4344 opts HookExecOpts
45+ setup func (afero.Fs )
4446 check func (* testing.T , string , error , ExecInterface )
4547 }{
4648 "error if hook command unavailable" : {
@@ -132,6 +134,29 @@ func Test_Hook_Execute_V2_Protocol(t *testing.T) {
132134 )
133135 },
134136 },
137+ "dotenv vars and hook vars are loaded into the environment" : {
138+ opts : HookExecOpts {
139+ Hook : HookScript {Name : "happypath" , Command : "echo {}" },
140+ Env : map [string ]string {
141+ "OPTS_VAR" : "from_opts" ,
142+ },
143+ Exec : & MockExec {
144+ mockCommand : & MockCommand {
145+ MockStdout : []byte (mockBoundaryString + `{"ok": true}` + mockBoundaryString ),
146+ Err : nil ,
147+ },
148+ },
149+ },
150+ setup : func (fs afero.Fs ) {
151+ _ = afero .WriteFile (fs , ".env" , []byte ("DOTENV_VAR=from_dotenv\n " ), 0600 )
152+ },
153+ check : func (t * testing.T , response string , err error , mockExec ExecInterface ) {
154+ require .NoError (t , err )
155+ require .Equal (t , `{"ok": true}` , response )
156+ require .Contains (t , mockExec .(* MockExec ).mockCommand .Env , `DOTENV_VAR=from_dotenv` )
157+ require .Contains (t , mockExec .(* MockExec ).mockCommand .Env , `OPTS_VAR=from_opts` )
158+ },
159+ },
135160 "fail to parse payload due to improper boundary strings" : {
136161 opts : HookExecOpts {
137162 Hook : HookScript {Name : "happypath" , Command : "echo {}" },
@@ -176,8 +201,13 @@ func Test_Hook_Execute_V2_Protocol(t *testing.T) {
176201 config := config .NewConfig (fs , os )
177202 ios := iostreams .NewIOStreamsMock (config , fs , os )
178203 ios .AddDefaultMocks ()
204+ memFs := afero .NewMemMapFs ()
179205 hookExecutor := & HookExecutorMessageBoundaryProtocol {
180206 IO : ios ,
207+ Fs : memFs ,
208+ }
209+ if tc .setup != nil {
210+ tc .setup (memFs )
181211 }
182212 response , err := hookExecutor .Execute (ctx , tc .opts )
183213 tc .check (t , response , err , tc .opts .Exec )
0 commit comments