-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLOUDP-70043: mongocli ops-manager|cloud-manager maintenanceWindow(s)…
… describe <ID> (#430)
- Loading branch information
1 parent
e9608f4
commit 042a0d3
Showing
7 changed files
with
196 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// 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 maintenance | ||
|
||
import ( | ||
"github.com/mongodb/mongocli/internal/cli" | ||
"github.com/mongodb/mongocli/internal/config" | ||
"github.com/mongodb/mongocli/internal/flag" | ||
"github.com/mongodb/mongocli/internal/store" | ||
"github.com/mongodb/mongocli/internal/usage" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type DescribeOpts struct { | ||
cli.GlobalOpts | ||
cli.OutputOpts | ||
id string | ||
store store.OpsManagerMaintenanceWindowDescriber | ||
} | ||
|
||
func (opts *DescribeOpts) initStore() error { | ||
var err error | ||
opts.store, err = store.New(config.Default()) | ||
return err | ||
} | ||
|
||
var describeTemplate = `ID PROJECT ID START DATE END DATE | ||
{{.ID}} {{.GroupID}} {{.StartDate}} {{.EndDate}} | ||
` | ||
|
||
func (opts *DescribeOpts) Run() error { | ||
r, err := opts.store.OpsManagerMaintenanceWindow(opts.ConfigProjectID(), opts.id) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return opts.Print(r) | ||
} | ||
|
||
// mongocli ops-manager maintenanceWindows describe <ID> [--projectId projectId] | ||
func DescribeBuilder() *cobra.Command { | ||
opts := &DescribeOpts{} | ||
cmd := &cobra.Command{ | ||
Use: "describe <ID>", | ||
Short: describeMaintenanceWindow, | ||
Args: cobra.ExactArgs(1), | ||
PreRunE: func(cmd *cobra.Command, args []string) error { | ||
return opts.PreRunE( | ||
opts.initStore, | ||
opts.InitOutput(cmd.OutOrStdout(), describeTemplate), | ||
) | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
opts.id = args[0] | ||
return opts.Run() | ||
}, | ||
} | ||
|
||
cmd.Flags().StringVar(&opts.ProjectID, flag.ProjectID, "", usage.ProjectID) | ||
cmd.Flags().StringVarP(&opts.Output, flag.Output, flag.OutputShort, "", usage.FormatOut) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// 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. | ||
|
||
// +build unit | ||
|
||
package maintenance | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/golang/mock/gomock" | ||
"github.com/mongodb/mongocli/internal/cli" | ||
"github.com/mongodb/mongocli/internal/flag" | ||
"github.com/mongodb/mongocli/internal/mocks" | ||
"go.mongodb.org/ops-manager/opsmngr" | ||
) | ||
|
||
func TestDescribe_Run(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
mockStore := mocks.NewMockOpsManagerMaintenanceWindowDescriber(ctrl) | ||
defer ctrl.Finish() | ||
|
||
expected := &opsmngr.MaintenanceWindow{} | ||
|
||
opts := &DescribeOpts{ | ||
store: mockStore, | ||
} | ||
|
||
mockStore. | ||
EXPECT(). | ||
OpsManagerMaintenanceWindow(opts.ProjectID, opts.id). | ||
Return(expected, nil). | ||
Times(1) | ||
|
||
err := opts.Run() | ||
if err != nil { | ||
t.Fatalf("Run() unexpected error: %v", err) | ||
} | ||
} | ||
|
||
func TestDescrieBuilder(t *testing.T) { | ||
cli.CmdValidator( | ||
t, | ||
DescribeBuilder(), | ||
0, | ||
[]string{flag.ProjectID}, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ func TestBuilder(t *testing.T) { | |
cli.CmdValidator( | ||
t, | ||
Builder(), | ||
3, | ||
4, | ||
[]string{}, | ||
) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters