Skip to content

Commit d70553a

Browse files
committed
fix: incorrect error handling in org id default function
1 parent 1959290 commit d70553a

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

pkg/app/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func defaultFuncOrganization(engine workflow.Engine, config configuration.Config
7373
logger.Print("Failed to determine default value for \"ORGANIZATION\":", err)
7474
}
7575

76-
return orgId, nil
76+
return orgId, err
7777
}
7878
return callback
7979
}

pkg/app/app_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
214247
func Test_initConfiguration_useDefaultOrgAsFallback(t *testing.T) {
215248
orgName := "someOrgName"
216249
defaultOrgId := "someDefaultOrgId"

0 commit comments

Comments
 (0)