Skip to content

Commit

Permalink
CLOUDP-220676: NPE in default_setter_opts.go (#2537)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaangiolillo authored Jan 3, 2024
1 parent 6b393d6 commit 77c94f9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/cli/default_setter_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (opts *DefaultSetterOpts) orgs(filter string) (results interface{}, err err
}
switch r := orgs.(type) {
case *atlasv2.PaginatedOrganization:
if *r.TotalCount == 0 {
if r.TotalCount == nil || *r.TotalCount == 0 {
return nil, errNoResults
}
if *r.TotalCount > resultsLimit {
Expand Down
17 changes: 17 additions & 0 deletions internal/cli/default_setter_opts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,21 @@ func TestDefaultOpts_Orgs(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, expectedOrgs.Results, gotOrgs)
})

t.Run("with no org", func(t *testing.T) {
expectedOrgs := &atlas.Organizations{
Results: []*atlas.Organization{},
}
mockStore.EXPECT().Organizations(gomock.Any()).Return(expectedOrgs, nil).Times(1)
_, err := opts.orgs("")
require.Error(t, err)
require.EqualError(t, err, errNoResults.Error())
})

t.Run("with nil org", func(t *testing.T) {
mockStore.EXPECT().Organizations(gomock.Any()).Return(nil, nil).Times(1)
_, err := opts.orgs("")
require.Error(t, err)
require.EqualError(t, err, errNoResults.Error())
})
}

0 comments on commit 77c94f9

Please sign in to comment.