• 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

42.27
/internal/cli/deployments/pause.go
1
// Copyright 2023 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 deployments
16

17
import (
18
        "context"
19
        "errors"
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/clusters/connect"
24
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli/deployments/options"
25
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli/require"
26
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/flag"
27
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/log"
28
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/store"
29
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/usage"
30
        "github.com/spf13/cobra"
31
        atlasClustersPinned "go.mongodb.org/atlas-sdk/v20240530005/admin"
32
        atlasv2 "go.mongodb.org/atlas-sdk/v20250312018/admin"
33
)
34

35
//go:generate go tool go.uber.org/mock/mockgen -typed -destination=pause_mock_test.go -package=deployments -source=pause.go
36

37
type ClusterPauser interface {
38
        PauseCluster(string, string) (*atlasClustersPinned.AdvancedClusterDescription, error)
39
        PauseClusterLatest(string, string) (*atlasv2.ClusterDescription20240805, error)
40
        GetClusterAutoScalingConfig(string, string) (*atlasv2.ClusterDescriptionAutoScalingModeConfiguration, error)
41
}
42

43
type PauseOpts struct {
44
        cli.OutputOpts
45
        cli.ProjectOpts
46
        options.DeploymentOpts
47
        store ClusterPauser
48
}
49

50
const (
51
        pauseTemplate = "Pausing deployment '{{.Name}}'.\n"
52
)
53

54
var (
55
        errDeploymentIsNotIDLE = errors.New("deployment state is not IDLE")
56
)
57

58
func (opts *PauseOpts) initStore(ctx context.Context) func() error {
×
59
        return func() error {
×
60
                var err error
×
61
                opts.store, err = store.New(store.AuthenticatedPreset(config.Default()), store.WithContext(ctx))
×
62
                return err
×
63
        }
×
64
}
65

66
func (opts *PauseOpts) Run(ctx context.Context) error {
1✔
67
        deployment, err := opts.SelectDeployments(ctx, opts.ConfigProjectID(), options.IdleState)
1✔
68
        if err != nil {
1✔
69
                return err
×
70
        }
×
71

72
        if opts.IsLocalDeploymentType() {
2✔
73
                return opts.RunLocal(ctx, deployment)
1✔
74
        }
1✔
75

76
        return opts.RunAtlas()
1✔
77
}
78

79
func (opts *PauseOpts) RunLocal(ctx context.Context, deployment options.Deployment) error {
1✔
80
        // Collect UUID before pausing
1✔
81
        opts.DeploymentTelemetry.AppendDeploymentUUID()
1✔
82

1✔
83
        if err := opts.stopContainer(ctx, deployment); err != nil {
1✔
84
                return err
×
85
        }
×
86

87
        return opts.Print(
1✔
88
                atlasClustersPinned.AdvancedClusterDescription{
1✔
89
                        Name: &opts.DeploymentName,
1✔
90
                })
1✔
91
}
92

93
func (opts *PauseOpts) stopContainer(ctx context.Context, deployment options.Deployment) error {
1✔
94
        if deployment.StateName == connect.PausedState || deployment.StateName == connect.StoppedState {
1✔
95
                return nil
×
96
        }
×
97

98
        if deployment.StateName != options.IdleState {
1✔
99
                return errDeploymentIsNotIDLE
×
100
        }
×
101
        opts.StartSpinner()
1✔
102
        defer opts.StopSpinner()
1✔
103

1✔
104
        return opts.ContainerEngine.ContainerStop(ctx, opts.LocalMongodHostname())
1✔
105
}
106

107
func (opts *PauseOpts) RunAtlas() error {
1✔
108
        opts.StartSpinner()
1✔
109
        defer opts.StopSpinner()
1✔
110

1✔
111
        clusterAutoScalingConfig, err := opts.store.GetClusterAutoScalingConfig(opts.ConfigProjectID(), opts.DeploymentName)
1✔
112
        if err != nil || options.IsClusterWideScaling(clusterAutoScalingConfig.GetAutoScalingMode()) {
2✔
113
                opts.DeploymentTelemetry.AppendClusterWideScalingMode()
1✔
114
                r, err := opts.store.PauseCluster(opts.ConfigProjectID(), opts.DeploymentName)
1✔
115
                if err != nil {
1✔
116
                        return err
×
117
                }
×
118
                return opts.Print(r)
1✔
119
        }
120

121
        // If cluster is not cluster wide scaling, we use the latest API version
122
        opts.DeploymentTelemetry.AppendIndependentShardScalingMode()
1✔
123
        r, err := opts.store.PauseClusterLatest(opts.ConfigProjectID(), opts.DeploymentName)
1✔
124
        if err != nil {
1✔
125
                return err
×
126
        }
×
127

128
        return opts.Print(r)
1✔
129
}
130

131
func (opts *PauseOpts) PostRun() error {
1✔
132
        opts.DeploymentTelemetry.AppendDeploymentType()
1✔
133
        return opts.PostRunMessages()
1✔
134
}
1✔
135

136
func PauseBuilder() *cobra.Command {
×
137
        opts := &PauseOpts{}
×
138
        cmd := &cobra.Command{
×
139
                Use:     "pause <deploymentName>",
×
140
                Aliases: []string{"stop"},
×
141
                Short:   "Pause a deployment.",
×
142
                Deprecated: `This command has been deprecated and will be removed in a future release.
×
143

×
144
Please switch to the new command structure based on your target environment:
×
145
- For Atlas (cloud) deployments, use 'atlas cluster pause'.
×
146
- For Local (Docker) deployments, use 'atlas local pause'.
×
147
`,
×
148
                Args:    require.MaximumNArgs(1),
×
149
                GroupID: "all",
×
150
                Annotations: map[string]string{
×
151
                        "deploymentNameDesc": "Name of the deployment.",
×
152
                        "output":             pauseTemplate,
×
153
                },
×
154
                PreRunE: func(cmd *cobra.Command, _ []string) error {
×
155
                        opts.CredStore = config.Default()
×
156

×
157
                        return opts.PreRunE(
×
158
                                opts.initStore(cmd.Context()),
×
159
                                opts.InitStore(cmd.Context(), cmd.OutOrStdout()),
×
160
                                opts.InitOutput(log.Writer(), pauseTemplate))
×
161
                },
×
162
                RunE: func(cmd *cobra.Command, args []string) error {
×
163
                        if len(args) == 1 {
×
164
                                opts.DeploymentName = args[0]
×
165
                        }
×
166
                        return opts.Run(cmd.Context())
×
167
                },
168
                PostRunE: func(_ *cobra.Command, _ []string) error {
×
169
                        return opts.PostRun()
×
170
                },
×
171
        }
172

173
        opts.AddProjectOptsFlags(cmd)
×
174
        cmd.Flags().StringVar(&opts.DeploymentType, flag.TypeFlag, "", usage.DeploymentType)
×
175

×
176
        return cmd
×
177
}
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