@@ -10,6 +10,7 @@ import (
1010 "path/filepath"
1111 "runtime"
1212 "testing"
13+ "time"
1314
1415 "github.com/golang/mock/gomock"
1516 zlog "github.com/rs/zerolog/log"
@@ -211,6 +212,38 @@ func Test_initConfiguration_useDefaultOrg(t *testing.T) {
211212 assert .Equal (t , defaultOrgSlug , actualOrgSlug )
212213}
213214
215+ func Test_initConfiguration_failDefaultOrgLookup (t * testing.T ) {
216+ orgId := "someOrgId"
217+ // setup mock
218+ ctrl := gomock .NewController (t )
219+ mockApiClient := mocks .NewMockApiClient (ctrl )
220+
221+ // mock assertion
222+ mockApiClient .EXPECT ().Init (gomock .Any (), gomock .Any ()).AnyTimes ()
223+ mockApiClient .EXPECT ().GetDefaultOrgId ().Return ("" , errors .New ("error" )).Times (2 )
224+ mockApiClient .EXPECT ().GetDefaultOrgId ().Return (orgId , nil ).Times (1 )
225+
226+ config := configuration .NewWithOpts (configuration .WithCachingEnabled (10 * time .Second ))
227+ engine := workflow .NewWorkFlowEngine (config )
228+ apiClientFactory := func (url string , client * http.Client ) api.ApiClient {
229+ return mockApiClient
230+ }
231+ initConfiguration (engine , config , & zlog .Logger , apiClientFactory )
232+
233+ actualOrgId , orgIdError := config .GetStringWithError (configuration .ORGANIZATION )
234+ assert .Error (t , orgIdError )
235+ assert .Empty (t , actualOrgId )
236+
237+ actualOrgSlug , slugError := config .GetStringWithError (configuration .ORGANIZATION_SLUG )
238+ assert .Error (t , slugError )
239+ assert .Empty (t , actualOrgSlug )
240+
241+ // ensure that if the error resolves, a valid value is returned
242+ actualOrgId , orgIdError = config .GetStringWithError (configuration .ORGANIZATION )
243+ assert .NoError (t , orgIdError )
244+ assert .Equal (t , orgId , actualOrgId )
245+ }
246+
214247func Test_initConfiguration_useDefaultOrgAsFallback (t * testing.T ) {
215248 orgName := "someOrgName"
216249 defaultOrgId := "someDefaultOrgId"
0 commit comments