-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLOUDP-69181: mongocli atlas networking peering delete <peerId> (#365)
- Loading branch information
1 parent
38a05e2
commit e0a9d23
Showing
6 changed files
with
176 additions
and
4 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,69 @@ | ||
// 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 peering | ||
|
||
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 DeleteOpts struct { | ||
cli.GlobalOpts | ||
*cli.DeleteOpts | ||
store store.PeeringConnectionDeleter | ||
} | ||
|
||
func (opts *DeleteOpts) initStore() error { | ||
var err error | ||
opts.store, err = store.New(config.Default()) | ||
return err | ||
} | ||
|
||
func (opts *DeleteOpts) Run() error { | ||
return opts.Delete(opts.store.DeletePeeringConnection, opts.ConfigProjectID()) | ||
} | ||
|
||
// mongocli atlas networking peering delete <ID> --force [--projectId projectId] | ||
func DeleteBuilder() *cobra.Command { | ||
opts := &DeleteOpts{ | ||
DeleteOpts: cli.NewDeleteOpts("Peering connection '%s' deleted\n", "Peering connection not deleted"), | ||
} | ||
cmd := &cobra.Command{ | ||
Use: "delete <ID>", | ||
Aliases: []string{"rm"}, | ||
Short: deletePeeringConnection, | ||
Args: cobra.ExactArgs(1), | ||
PreRunE: func(cmd *cobra.Command, args []string) error { | ||
if err := opts.PreRunE(opts.initStore); err != nil { | ||
return err | ||
} | ||
opts.Entry = args[0] | ||
return opts.Prompt() | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return opts.Run() | ||
}, | ||
} | ||
|
||
cmd.Flags().BoolVar(&opts.Confirm, flag.Force, false, usage.Force) | ||
|
||
cmd.Flags().StringVar(&opts.ProjectID, flag.ProjectID, "", usage.ProjectID) | ||
|
||
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,49 @@ | ||
// 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 peering | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/golang/mock/gomock" | ||
"github.com/mongodb/mongocli/internal/cli" | ||
"github.com/mongodb/mongocli/internal/mocks" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestDelete_Run(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
mockStore := mocks.NewMockPeeringConnectionDeleter(ctrl) | ||
defer ctrl.Finish() | ||
|
||
deleteOpts := &DeleteOpts{ | ||
DeleteOpts: &cli.DeleteOpts{ | ||
Entry: "to_delete", | ||
Confirm: true, | ||
}, | ||
store: mockStore, | ||
} | ||
|
||
mockStore. | ||
EXPECT(). | ||
DeletePeeringConnection(deleteOpts.ProjectID, deleteOpts.Entry). | ||
Return(nil). | ||
Times(1) | ||
|
||
err := deleteOpts.Run() | ||
assert.NoError(t, err) | ||
} |
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 |
---|---|---|
|
@@ -26,6 +26,7 @@ func Builder() *cobra.Command { | |
} | ||
|
||
cmd.AddCommand(ListBuilder()) | ||
cmd.AddCommand(DeleteBuilder()) | ||
|
||
return cmd | ||
} |
39 changes: 38 additions & 1 deletion
39
internal/mocks/mock_peeringConnections.go → internal/mocks/mock_peering_connections.go
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