-
Notifications
You must be signed in to change notification settings - Fork 87
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
Changes from 9 commits
f1cce52
16524e1
f350cd6
ec2d5cc
71a4332
3d4fa78
b544509
9090190
cae7df6
495464a
b5949fb
9ab485f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ | |
package cli | ||
|
||
import ( | ||
om "github.com/mongodb/go-client-mongodb-ops-manager/opsmngr" | ||
"github.com/mongodb/mongocli/internal/config" | ||
"github.com/mongodb/mongocli/internal/convert" | ||
"github.com/mongodb/mongocli/internal/flags" | ||
"github.com/mongodb/mongocli/internal/json" | ||
|
@@ -23,36 +25,41 @@ import ( | |
"github.com/spf13/cobra" | ||
) | ||
|
||
type cmClustersListOpts struct { | ||
type cloudManagerClustersListOpts struct { | ||
*globalOpts | ||
store store.AutomationGetter | ||
store store.CloudManagerClustersLister | ||
} | ||
|
||
func (opts *cmClustersListOpts) init() error { | ||
if opts.ProjectID() == "" { | ||
return errMissingProjectID | ||
} | ||
|
||
func (opts *cloudManagerClustersListOpts) init() error { | ||
var err error | ||
opts.store, err = store.New() | ||
return err | ||
} | ||
|
||
func (opts *cmClustersListOpts) Run() error { | ||
result, err := opts.store.GetAutomationConfig(opts.ProjectID()) | ||
func (opts *cloudManagerClustersListOpts) Run() error { | ||
|
||
var result interface{} | ||
var err error | ||
|
||
if opts.projectID == "" && config.Service() == config.OpsManagerService { | ||
result, err = opts.store.ListAllClustersProjects() | ||
|
||
} else { | ||
var clusterConfigs *om.AutomationConfig | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
clusterConfigs, err = opts.store.GetAutomationConfig(opts.ProjectID()) | ||
result = convert.FromAutomationConfig(clusterConfigs) | ||
} | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
clusterConfigs := convert.FromAutomationConfig(result) | ||
|
||
return json.PrettyPrint(clusterConfigs) | ||
return json.PrettyPrint(result) | ||
} | ||
|
||
// mongocli cloud-manager cluster(s) list --projectId projectId | ||
func CloudManagerClustersListBuilder() *cobra.Command { | ||
opts := &cmClustersListOpts{ | ||
opts := &cloudManagerClustersListOpts{ | ||
globalOpts: newGlobalOpts(), | ||
} | ||
cmd := &cobra.Command{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 |
||
"github.com/golang/mock/gomock" | ||
"github.com/mongodb/mongocli/internal/fixtures" | ||
"github.com/mongodb/mongocli/internal/mocks" | ||
) | ||
|
||
func TestCloudManagerClustersList_Run(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
mockStore := mocks.NewMockAutomationGetter(ctrl) | ||
mockStore := mocks.NewMockCloudManagerClustersLister(ctrl) | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. brilliant 💯 |
||
expected := fixtures.AutomationConfig() | ||
|
||
listOpts := &cloudManagerClustersListOpts{ | ||
globalOpts: newGlobalOpts(), | ||
store: mockStore, | ||
} | ||
|
||
listOpts.projectID = "1" | ||
mockStore. | ||
EXPECT(). | ||
GetAutomationConfig(listOpts.projectID). | ||
Return(expected, nil). | ||
Times(1) | ||
|
||
err := listOpts.Run() | ||
if err != nil { | ||
t.Fatalf("Run() unexpected error: %v", err) | ||
} | ||
|
||
}) | ||
|
||
t.Run("No ProjectID is given", func(t *testing.T) { | ||
expected := fixtures.AllClusters() | ||
config.SetService(config.OpsManagerService) | ||
mockStore. | ||
EXPECT(). | ||
ListAllClustersProjects(). | ||
Return(expected, nil). | ||
Times(1) | ||
|
||
listOpts := &cmClustersListOpts{ | ||
globalOpts: newGlobalOpts(), | ||
store: mockStore, | ||
} | ||
listOpts := &cloudManagerClustersListOpts{ | ||
globalOpts: newGlobalOpts(), | ||
store: mockStore, | ||
} | ||
|
||
mockStore. | ||
EXPECT(). | ||
GetAutomationConfig(listOpts.projectID). | ||
Return(expected, nil). | ||
Times(1) | ||
err := listOpts.Run() | ||
if err != nil { | ||
t.Fatalf("Run() unexpected error: %v", err) | ||
} | ||
}) | ||
|
||
err := listOpts.Run() | ||
if err != nil { | ||
t.Fatalf("Run() unexpected error: %v", err) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// Copyright 2020 MongoDB Inc | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
package fixtures | ||
|
||
import ( | ||
atlas "github.com/mongodb/go-client-mongodb-atlas/mongodbatlas" | ||
om "github.com/mongodb/go-client-mongodb-ops-manager/opsmngr" | ||
) | ||
|
||
func AllClusters() *om.AllClustersProjects { | ||
return &om.AllClustersProjects{ | ||
Links: []*atlas.Link{}, | ||
Results: []*om.AllClustersProject{ | ||
{ | ||
GroupName: "AtlasGroup1", | ||
OrgName: "TestAtlasOrg1", | ||
PlanType: "Atlas", | ||
GroupID: "5e5fbc29e76c9a4be2ed3d39", | ||
OrgID: "5e5fbc29e76c9a4be2ed3d36", | ||
Clusters: []om.AllClustersCluster{ | ||
{ | ||
ClusterID: "5e5fbc29e76c9a4be2ed3d4d", | ||
Name: "AtlasCluster1", | ||
Type: "sharded cluster", | ||
Availability: "unavailable", | ||
Versions: []string{"3.4.2"}, | ||
BackupEnabled: true, | ||
AuthEnabled: true, | ||
SSLEnabled: true, | ||
AlertCount: 0, | ||
DataSizeBytes: 1000000, | ||
NodeCount: 7, | ||
}, | ||
{ | ||
ClusterID: "5e5fbc29e76c9a4be2ed3d4f", | ||
Name: "AtlasReplSet1", | ||
Type: "replica set", | ||
Availability: "dead", | ||
Versions: []string{"3.4.1"}, | ||
BackupEnabled: false, | ||
AuthEnabled: true, | ||
SSLEnabled: true, | ||
AlertCount: 0, | ||
DataSizeBytes: 1300000, | ||
NodeCount: 2, | ||
}, | ||
}, | ||
}, | ||
{ | ||
GroupName: "CloudGroup1", | ||
OrgName: "TestCloudOrg1", | ||
PlanType: "Cloud Manager", | ||
GroupID: "5e5fbc29e76c9a4be2ed3d38", | ||
OrgID: "5e5fbc29e76c9a4be2ed3d34", | ||
Tags: []string{"some tag 1", "some tag 2"}, | ||
Clusters: []om.AllClustersCluster{ | ||
{ | ||
ClusterID: "5e5fbc29e76c9a4be2ed3d42", | ||
Name: "cluster1", | ||
Type: "sharded cluster", | ||
Availability: "warning", | ||
Versions: []string{"3.4.1", "2.4.3"}, | ||
BackupEnabled: true, | ||
AuthEnabled: false, | ||
SSLEnabled: false, | ||
AlertCount: 0, | ||
DataSizeBytes: 1000000, | ||
NodeCount: 6, | ||
}, | ||
{ | ||
ClusterID: "5e5fbc29e76c9a4be2ed3d3c", | ||
Name: "replica_set", | ||
Type: "replica set", | ||
Availability: "available", | ||
Versions: []string{"3.4.1"}, | ||
BackupEnabled: true, | ||
AuthEnabled: true, | ||
SSLEnabled: true, | ||
AlertCount: 0, | ||
DataSizeBytes: 500000, | ||
NodeCount: 2, | ||
}, | ||
{ | ||
ClusterID: "da303f3fec69b2100bacf10dd9e6d5e0", | ||
Name: "standalone:27017", | ||
Type: "standalone", | ||
Availability: "unavailable", | ||
Versions: []string{"2.4.3"}, | ||
BackupEnabled: false, | ||
AuthEnabled: false, | ||
SSLEnabled: true, | ||
AlertCount: 0, | ||
DataSizeBytes: 2000000, | ||
NodeCount: 1, | ||
}, | ||
}, | ||
}, | ||
}, | ||
TotalCount: 2, | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 👍