• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mongodb / mongodb-atlas-cli / 25848964073

14 May 2026 07:59AM UTC coverage: 22.479% (-41.3%) from 63.771%
25848964073

push

github

web-flow
build(deps): bump test-summary/action from 2.4 to 2.6 (#4576)

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

8987 of 39979 relevant lines covered (22.48%)

0.25 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

15.69
/internal/cli/clusters/pause.go
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 clusters
16

17
import (
18
        "context"
19
        "fmt"
20

21
        "github.com/mongodb/atlas-cli-core/config"
22
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli"
23
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli/require"
24
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/flag"
25
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/store"
26
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/usage"
27
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/validate"
28
        "github.com/spf13/cobra"
29
        atlasClustersPinned "go.mongodb.org/atlas-sdk/v20240530005/admin"
30
        atlasv2 "go.mongodb.org/atlas-sdk/v20250312018/admin"
31
)
32

33
//go:generate go tool go.uber.org/mock/mockgen -typed -destination=pause_mock_test.go -package=clusters -source=pause.go
34

35
type ClusterPauser interface {
36
        PauseCluster(string, string) (*atlasClustersPinned.AdvancedClusterDescription, error)
37
        PauseClusterLatest(string, string) (*atlasv2.ClusterDescription20240805, error)
38
}
39

40
type PauseOpts struct {
41
        cli.ProjectOpts
42
        cli.OutputOpts
43
        name            string
44
        autoScalingMode string
45
        store           ClusterPauser
46
}
47

48
func (opts *PauseOpts) initStore(ctx context.Context) func() error {
×
49
        return func() error {
×
50
                var err error
×
51
                opts.store, err = store.New(store.AuthenticatedPreset(config.Default()), store.WithContext(ctx))
×
52
                return err
×
53
        }
×
54
}
55

56
var pauseTmpl = "Pausing cluster '{{.Name}}'.\n"
57

58
func (opts *PauseOpts) Run() error {
1✔
59
        if isIndependentShardScaling(opts.autoScalingMode) {
2✔
60
                r, err := opts.store.PauseClusterLatest(opts.ConfigProjectID(), opts.name)
1✔
61
                if err != nil {
1✔
62
                        return err
×
63
                }
×
64
                return opts.Print(r)
1✔
65
        }
66

67
        r, err := opts.store.PauseCluster(opts.ConfigProjectID(), opts.name)
1✔
68
        if err != nil {
1✔
69
                return err
×
70
        }
×
71
        return opts.Print(r)
1✔
72
}
73

74
// atlas cluster(s) pause <clusterName> [--projectId projectId].
75
func PauseBuilder() *cobra.Command {
×
76
        opts := &PauseOpts{}
×
77
        cmd := &cobra.Command{
×
78
                Use:   "pause <clusterName>",
×
79
                Short: "Pause the specified running MongoDB cluster.",
×
80
                Long:  fmt.Sprintf("%s\n%s", fmt.Sprintf(usage.RequiredRole, "Project Cluster Manager"), "Atlas supports this command only for M10+ clusters."),
×
81
                Args:  require.ExactArgs(1),
×
82
                Annotations: map[string]string{
×
83
                        "clusterNameDesc": "Name of the cluster to pause.",
×
84
                        "output":          pauseTmpl,
×
85
                },
×
86
                Example: `  # Pause the cluster named myCluster for the project with ID 5e2211c17a3e5a48f5497de3:
×
87
  atlas clusters pause myCluster --projectId 5e2211c17a3e5a48f5497de3 --output json`,
×
88
                PreRunE: func(cmd *cobra.Command, _ []string) error {
×
89
                        return opts.PreRunE(
×
90
                                opts.ValidateProjectID,
×
91
                                opts.initStore(cmd.Context()),
×
92
                                opts.InitOutput(cmd.OutOrStdout(), pauseTmpl),
×
93
                                validate.AutoScalingMode(opts.autoScalingMode),
×
94
                        )
×
95
                },
×
96
                RunE: func(_ *cobra.Command, args []string) error {
×
97
                        opts.name = args[0]
×
98
                        return opts.Run()
×
99
                },
×
100
        }
101

102
        cmd.Flags().StringVar(&opts.autoScalingMode, flag.AutoScalingMode, clusterWideScalingFlag, usage.AutoScalingMode)
×
103
        _ = cmd.RegisterFlagCompletionFunc(flag.AutoScalingMode, func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
×
104
                return []string{clusterWideScalingFlag, independentShardScalingFlag}, cobra.ShellCompDirectiveDefault
×
105
        })
×
106

107
        opts.AddProjectOptsFlags(cmd)
×
108
        opts.AddOutputOptFlags(cmd)
×
109

×
110
        return cmd
×
111
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc