Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLOUDP-220676: NPE in default_setter_opts.go #2537

Merged
merged 3 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
tibulca marked this conversation as resolved.
Show resolved Hide resolved
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())
})
}