-
Notifications
You must be signed in to change notification settings - Fork 86
CLOUDP-56480: Clusters list command should return all clusters #45
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
Conversation
@@ -23,23 +23,26 @@ import ( | |||
"github.com/spf13/cobra" | |||
) | |||
|
|||
type cmClustersListOpts struct { | |||
type clustersListOpts struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to change the name since this is also used by OM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you want to rename this do it to cloudManagerClustersListOpts
I'm not that worried about it being shared as they are both the same, at some point ops-manager
was an alias for cloud-manager
but we were asked to give it its own space
We may eventually rename all to opsManager
and files along or like we discussed find a new way to organize these commands (folders/packages?) so feel free of start thinking on those
if err != nil { | ||
t.Fatalf("Run() unexpected error: %v", err) | ||
} | ||
} | ||
|
||
func TestCloudManagerAllClustersProjectsList_Run(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we change the name since this is also used by only OM?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a lot to be done but it all comes from defining two stores when you only need one
Also let's not do atlas until we have that support in the atlas client
internal/cli/atlas_clusters_list.go
Outdated
@@ -27,22 +27,25 @@ type atlasClustersListOpts struct { | |||
*globalOpts | |||
pageNum int | |||
itemsPerPage int | |||
store store.ClusterLister | |||
storeAT store.ClusterLister |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's no need to create a new store, just create a new interface that defines the two methods you need
internal/cli/atlas_clusters_list.go
Outdated
if opts.ProjectID() == "" { | ||
return errMissingProjectID | ||
opts.storeOM, err = store.New() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
store.New() implements all the methods of available this if is big code smell that you probably just need a new contract atlasClustersListOpts
and not multiple fields, see my previous comment
internal/cli/atlas_clusters_list.go
Outdated
return err | ||
} | ||
|
||
func (opts *atlasClustersListOpts) Run() error { | ||
func (opts *atlasClustersListOpts) RunAT() error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this all comes from the same thing, multiple properties instead of a more flexible contract, there's no need to have multiple Run
methods
if err != nil { | ||
t.Fatalf("Run() unexpected error: %v", err) | ||
} | ||
} | ||
|
||
func TestAtlasAllClustersProjectsList_Run(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't need a new test function, you should just define a new scenario
this block should be able to live in the already existing function
t.Run("List all clusters projects", func(t *testing.T) {...}
"github.com/mongodb/mongocli/internal/config" | ||
) | ||
|
||
type ListAllClusters interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's a go convention to name single method interfaces as er
adjectives, this should be AllClustersLister
// ListAllClustersProjects encapsulate the logic to manage different cloud providers | ||
func (s *Store) ListAllClustersProjects() (*om.AllClustersProjects, error) { | ||
switch s.service { | ||
case config.OpsManagerService: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should support CloudManagerService
as well as is the same API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks so much better now, all code is good, let's just fix the formatting of the imports on the test file
result, err = opts.store.ListAllClustersProjects() | ||
|
||
} else { | ||
var clusterConfigs *om.AutomationConfig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[np] this could be a function but feel free to ignore unless you want to do other changes
func (opts *cloudManagerClustersListOpts) Run() error { | ||
|
||
var result interface{} | ||
var err error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good use of a programatic error 👍
|
||
defer ctrl.Finish() | ||
|
||
expected := fixtures.AutomationConfig() | ||
t.Run("ProjectID is given", func(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
brilliant 💯
@@ -17,32 +17,59 @@ package cli | |||
import ( | |||
"testing" | |||
|
|||
"github.com/mongodb/mongocli/internal/config" | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small thing, extra empty line, let's remove it and fmtimport this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Jira ticket: CLOUDP-56480