Skip to content

Commit c8d11d9

Browse files
authored
CLOUDP-59811: Show automation config (#76)
1 parent cdf4d72 commit c8d11d9

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed

internal/cli/ops_manager_automation.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ func OpsManagerAutomationBuilder() *cobra.Command {
2626
}
2727

2828
cmd.AddCommand(OpsManagerAutomationStatusBuilder())
29+
cmd.AddCommand(OpsManagerAutomationShowBuilder())
2930
return cmd
3031
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright 2020 MongoDB Inc
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package cli
16+
17+
import (
18+
"github.com/mongodb/mongocli/internal/flags"
19+
"github.com/mongodb/mongocli/internal/json"
20+
"github.com/mongodb/mongocli/internal/store"
21+
"github.com/mongodb/mongocli/internal/usage"
22+
"github.com/spf13/cobra"
23+
)
24+
25+
type opsManagerAutomationShowOpts struct {
26+
*globalOpts
27+
store store.AutomationGetter
28+
}
29+
30+
func (opts *opsManagerAutomationShowOpts) init() error {
31+
if opts.ProjectID() == "" {
32+
return errMissingProjectID
33+
}
34+
var err error
35+
opts.store, err = store.New()
36+
return err
37+
}
38+
39+
func (opts *opsManagerAutomationShowOpts) Run() error {
40+
r, err := opts.store.GetAutomationConfig(opts.projectID)
41+
42+
if err != nil {
43+
return err
44+
}
45+
46+
return json.PrettyPrint(r)
47+
}
48+
49+
// mongocli ops-manager automation show [--projectId projectId]
50+
func OpsManagerAutomationShowBuilder() *cobra.Command {
51+
opts := &opsManagerAutomationShowOpts{
52+
globalOpts: newGlobalOpts(),
53+
}
54+
cmd := &cobra.Command{
55+
Use: "show",
56+
Args: cobra.NoArgs,
57+
Hidden: true,
58+
PreRunE: func(cmd *cobra.Command, args []string) error {
59+
return opts.init()
60+
},
61+
RunE: func(cmd *cobra.Command, args []string) error {
62+
return opts.Run()
63+
},
64+
}
65+
66+
cmd.Flags().StringVar(&opts.projectID, flags.ProjectID, "", usage.ProjectID)
67+
68+
return cmd
69+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2020 MongoDB Inc
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package cli
16+
17+
import (
18+
"testing"
19+
20+
"github.com/golang/mock/gomock"
21+
"github.com/mongodb/mongocli/internal/fixtures"
22+
"github.com/mongodb/mongocli/internal/mocks"
23+
)
24+
25+
func TestOpsManagerAutomationShowOpts_Run(t *testing.T) {
26+
ctrl := gomock.NewController(t)
27+
mockStore := mocks.NewMockAutomationGetter(ctrl)
28+
29+
defer ctrl.Finish()
30+
31+
expected := fixtures.AutomationConfig()
32+
33+
opts := &opsManagerAutomationShowOpts{
34+
globalOpts: newGlobalOpts(),
35+
store: mockStore,
36+
}
37+
38+
mockStore.
39+
EXPECT().
40+
GetAutomationConfig(opts.projectID).
41+
Return(expected, nil).
42+
Times(1)
43+
44+
err := opts.Run()
45+
if err != nil {
46+
t.Fatalf("Run() unexpected error: %v", err)
47+
}
48+
}

0 commit comments

Comments
 (0)