@@ -191,17 +191,42 @@ func Test_Os_LookupEnv(t *testing.T) {
191191 }
192192}
193193
194- func Test_Os_SetenvUnsetenv (t * testing.T ) {
195- o := NewOs ()
196- key := "SLACK_TEST_OS_SETENV"
197-
198- err := o .Setenv (key , "test_value" )
199- require .NoError (t , err )
200- require .Equal (t , "test_value" , o .Getenv (key ))
201-
202- err = o .Unsetenv (key )
203- require .NoError (t , err )
204- require .Equal (t , "" , o .Getenv (key ))
194+ func Test_Os_Setenv (t * testing.T ) {
195+ tests := map [string ]struct {
196+ key string
197+ value string
198+ initialValue string
199+ expected string
200+ }{
201+ "sets a new env var" : {
202+ key : "SLACK_TEST_OS_SETENV_NEW" ,
203+ value : "hello" ,
204+ expected : "hello" ,
205+ },
206+ "overwrites an existing env var" : {
207+ key : "SLACK_TEST_OS_SETENV_OVERWRITE" ,
208+ value : "updated" ,
209+ initialValue : "original" ,
210+ expected : "updated" ,
211+ },
212+ "sets an empty value" : {
213+ key : "SLACK_TEST_OS_SETENV_EMPTY" ,
214+ value : "" ,
215+ expected : "" ,
216+ },
217+ }
218+ for name , tc := range tests {
219+ t .Run (name , func (t * testing.T ) {
220+ o := NewOs ()
221+ if tc .initialValue != "" {
222+ t .Setenv (tc .key , tc .initialValue )
223+ }
224+ err := o .Setenv (tc .key , tc .value )
225+ require .NoError (t , err )
226+ require .Equal (t , tc .expected , o .Getenv (tc .key ))
227+ t .Cleanup (func () { o .Unsetenv (tc .key ) })
228+ })
229+ }
205230}
206231
207232func Test_Os_Stdout (t * testing.T ) {
0 commit comments