@@ -10,6 +10,7 @@ import (
10
10
"path/filepath"
11
11
"runtime"
12
12
"testing"
13
+ "time"
13
14
14
15
"github.com/golang/mock/gomock"
15
16
zlog "github.com/rs/zerolog/log"
@@ -211,6 +212,38 @@ func Test_initConfiguration_useDefaultOrg(t *testing.T) {
211
212
assert .Equal (t , defaultOrgSlug , actualOrgSlug )
212
213
}
213
214
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
+
214
247
func Test_initConfiguration_useDefaultOrgAsFallback (t * testing.T ) {
215
248
orgName := "someOrgName"
216
249
defaultOrgId := "someDefaultOrgId"
0 commit comments