Skip to content

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

Merged
merged 12 commits into from
Mar 13, 2020

Conversation

andreaangiolillo
Copy link
Collaborator

Jira ticket: CLOUDP-56480

@andreaangiolillo andreaangiolillo added the WIP Work in progress label Mar 12, 2020
@@ -23,23 +23,26 @@ import (
"github.com/spf13/cobra"
)

type cmClustersListOpts struct {
type clustersListOpts struct {
Copy link
Collaborator Author

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

Copy link
Collaborator

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) {
Copy link
Collaborator Author

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?

@andreaangiolillo andreaangiolillo requested a review from gssbzn March 12, 2020 16:37
@andreaangiolillo andreaangiolillo removed the WIP Work in progress label Mar 12, 2020
Copy link
Collaborator

@gssbzn gssbzn left a 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

@@ -27,22 +27,25 @@ type atlasClustersListOpts struct {
*globalOpts
pageNum int
itemsPerPage int
store store.ClusterLister
storeAT store.ClusterLister
Copy link
Collaborator

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

if opts.ProjectID() == "" {
return errMissingProjectID
opts.storeOM, err = store.New()
Copy link
Collaborator

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

return err
}

func (opts *atlasClustersListOpts) Run() error {
func (opts *atlasClustersListOpts) RunAT() error {
Copy link
Collaborator

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) {
Copy link
Collaborator

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 {
Copy link
Collaborator

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:
Copy link
Collaborator

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

@andreaangiolillo andreaangiolillo requested a review from gssbzn March 12, 2020 18:41
Copy link
Collaborator

@gssbzn gssbzn left a 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
Copy link
Collaborator

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
Copy link
Collaborator

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) {
Copy link
Collaborator

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"

Copy link
Collaborator

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

@andreaangiolillo andreaangiolillo requested a review from gssbzn March 13, 2020 10:36
Copy link
Collaborator

@gssbzn gssbzn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@andreaangiolillo andreaangiolillo merged commit 1b56d3d into master Mar 13, 2020
@andreaangiolillo andreaangiolillo deleted the CLOUDP-56480 branch March 13, 2020 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants