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

mongodb / mongodb-atlas-cli / 16676051150

01 Aug 2025 01:09PM UTC coverage: 57.898% (-0.06%) from 57.953%
16676051150

Pull #4074

github

Waybo26
CLOUDP-334886: create stub for workspace update command in Atlas CLI
Pull Request #4074: CLOUDP-334886: create stub for workspace update command

0 of 40 new or added lines in 2 files covered. (0.0%)

41 existing lines in 1 file now uncovered.

23613 of 40784 relevant lines covered (57.9%)

2.74 hits per line

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

60.19
/internal/cli/streams/instance/update.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 instance
16

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

21
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli"
22
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli/require"
23
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/config"
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/spf13/cobra"
28
        atlasv2 "go.mongodb.org/atlas-sdk/v20250312005/admin"
29
)
30

31
//go:generate go tool go.uber.org/mock/mockgen -typed -destination=update_mock_test.go -package=instance . StreamsUpdater
32

33
type StreamsUpdater interface {
34
        UpdateStream(string, string, *atlasv2.StreamsDataProcessRegion) (*atlasv2.StreamsTenant, error)
35
}
36

37
type UpdateOpts struct {
38
        cli.ProjectOpts
39
        cli.OutputOpts
40
        cli.InputOpts
41
        name        string
42
        provider    string
43
        region      string
44
        tier        string
45
        defaultTier string
46
        maxTierSize string
47
        store       StreamsUpdater
48
}
49

50
const (
51
        updateTemplate          = "Atlas Streams Processor Instance '{{.Name}}' successfully updated.\n"
52
        updateTemplateWorkspace = "Atlas Streams Processor Workspace '{{.Name}}' successfully updated.\n"
53
)
54

55
func (opts *UpdateOpts) Run() error {
1✔
56
        stream := opts.streams()
1✔
57
        r, err := opts.store.UpdateStream(opts.ProjectID, opts.name, stream.DataProcessRegion)
1✔
58

1✔
59
        if err != nil {
1✔
UNCOV
60
                return err
×
UNCOV
61
        }
×
62

63
        return opts.Print(r)
1✔
64
}
65

66
func (opts *UpdateOpts) streams() *atlasv2.StreamsTenant {
1✔
67
        processor := atlasv2.NewStreamsTenant()
1✔
68
        processor.Name = &opts.name
1✔
69
        processor.GroupId = &opts.ProjectID
1✔
70

1✔
71
        processor.DataProcessRegion = atlasv2.NewStreamsDataProcessRegionWithDefaults()
1✔
72

1✔
73
        if opts.provider != "" {
2✔
74
                processor.DataProcessRegion.CloudProvider = opts.provider
1✔
75
        }
1✔
76

77
        if opts.region != "" {
2✔
78
                processor.DataProcessRegion.Region = opts.region
1✔
79
        }
1✔
80

81
        return processor
1✔
82
}
83

84
func (opts *UpdateOpts) initStore(ctx context.Context) func() error {
1✔
85
        return func() error {
2✔
86
                var err error
1✔
87
                opts.store, err = store.New(store.AuthenticatedPreset(config.Default()), store.WithContext(ctx))
1✔
88
                return err
1✔
89
        }
1✔
90
}
91

92
// CreateBuilder
93
// atlas streams instance update [name]
94
// --provider AWS
95
// --region VIRGINIA_USA.
96
func UpdateBuilder() *cobra.Command {
1✔
97
        opts := &UpdateOpts{}
1✔
98
        cmd := &cobra.Command{
1✔
99
                Use:   "update <name>",
1✔
100
                Short: "Updates an Atlas Stream Processing instance for your project.",
1✔
101
                Long: `Before updating an Atlas Streams Processing instance, you must first stop all processes associated with it.
1✔
102
` + fmt.Sprintf(usage.RequiredRole, "Project Owner"),
1✔
103
                Args: require.ExactArgs(1),
1✔
104
                Annotations: map[string]string{
1✔
105
                        "nameDesc": "Name of the Atlas Stream Processing instance. After creation, you can't change the name of the instance. The name can contain ASCII letters, numbers, and hyphens.",
1✔
106
                        "output":   updateTemplate,
1✔
107
                },
1✔
108
                Example: `  # Modify the Atlas Stream Processing instance configuration with the name MyInstance:
1✔
109
  atlas streams instance update MyInstance --provider AWS --region VIRGINIA_USA`,
1✔
110
                PreRunE: func(cmd *cobra.Command, args []string) error {
2✔
111
                        opts.name = args[0]
1✔
112

1✔
113
                        return opts.PreRunE(
1✔
114
                                opts.ValidateProjectID,
1✔
115
                                opts.initStore(cmd.Context()),
1✔
116
                                opts.InitOutput(cmd.OutOrStdout(), updateTemplate),
1✔
117
                        )
1✔
118
                },
1✔
119
                RunE: func(_ *cobra.Command, _ []string) error {
1✔
120
                        return opts.Run()
1✔
121
                },
1✔
122
        }
123

124
        cmd.Flags().StringVar(&opts.provider, flag.Provider, "AWS", usage.StreamsProvider)
1✔
125
        cmd.Flags().StringVarP(&opts.region, flag.Region, flag.RegionShort, "", usage.StreamsRegion)
1✔
126

1✔
127
        opts.AddProjectOptsFlags(cmd)
1✔
128
        opts.AddOutputOptFlags(cmd)
1✔
129

1✔
130
        _ = cmd.MarkFlagRequired(flag.Provider)
1✔
131
        _ = cmd.MarkFlagRequired(flag.Region)
1✔
132

1✔
133
        return cmd
1✔
134
}
135

NEW
UNCOV
136
func WorkspaceUpdateBuilder() *cobra.Command {
×
NEW
UNCOV
137
        opts := &UpdateOpts{}
×
NEW
UNCOV
138
        cmd := &cobra.Command{
×
NEW
UNCOV
139
                Use:   "update <name>",
×
NEW
UNCOV
140
                Short: "Updates an Atlas Stream Processing workspace for your project.",
×
NEW
UNCOV
141
                Long: `Before updating an Atlas Streams Processing workspace, you must first stop all processes associated with it.
×
NEW
UNCOV
142
` + fmt.Sprintf(usage.RequiredRole, "Project Owner"),
×
NEW
UNCOV
143
                Args: require.ExactArgs(1),
×
NEW
UNCOV
144
                Annotations: map[string]string{
×
NEW
UNCOV
145
                        "nameDesc": "Name of the Atlas Stream Processing workspace. After creation, you can't change the name of the workspace. The name can contain ASCII letters, numbers, and hyphens.",
×
NEW
UNCOV
146
                        "output":   updateTemplateWorkspace,
×
NEW
UNCOV
147
                },
×
NEW
UNCOV
148
                Example: `  # Modify the Atlas Stream Processing workspace configuration with the name MyWorkspace:
×
NEW
UNCOV
149
  atlas streams workspace update MyWorkspace --provider AWS --region VIRGINIA_USA`,
×
NEW
UNCOV
150
                PreRunE: func(cmd *cobra.Command, args []string) error {
×
NEW
UNCOV
151
                        opts.name = args[0]
×
NEW
UNCOV
152

×
NEW
UNCOV
153
                        return opts.PreRunE(
×
NEW
UNCOV
154
                                opts.ValidateProjectID,
×
NEW
UNCOV
155
                                opts.initStore(cmd.Context()),
×
NEW
UNCOV
156
                                opts.InitOutput(cmd.OutOrStdout(), updateTemplate),
×
NEW
UNCOV
157
                        )
×
NEW
UNCOV
158
                },
×
NEW
UNCOV
159
                RunE: func(_ *cobra.Command, _ []string) error {
×
NEW
UNCOV
160
                        return opts.Run()
×
NEW
UNCOV
161
                },
×
162
        }
163

NEW
UNCOV
164
        cmd.Flags().StringVar(&opts.provider, flag.Provider, "AWS", usage.StreamsProvider)
×
NEW
UNCOV
165
        cmd.Flags().StringVarP(&opts.region, flag.Region, flag.RegionShort, "", usage.StreamsRegion)
×
NEW
UNCOV
166
        cmd.Flags().StringVar(&opts.tier, flag.Tier, "", usage.StreamsWorkspaceTier)
×
NEW
UNCOV
167
        cmd.Flags().StringVar(&opts.defaultTier, flag.DefaultTier, "", usage.StreamsWorkspaceTier)
×
NEW
UNCOV
168
        cmd.Flags().StringVar(&opts.maxTierSize, flag.MaxTierSize, "", usage.StreamsWorkspaceMaxTierSize)
×
NEW
UNCOV
169

×
NEW
UNCOV
170
        opts.AddProjectOptsFlags(cmd)
×
NEW
UNCOV
171
        opts.AddOutputOptFlags(cmd)
×
NEW
UNCOV
172

×
NEW
UNCOV
173
        _ = cmd.MarkFlagRequired(flag.Provider)
×
NEW
UNCOV
174
        _ = cmd.MarkFlagRequired(flag.Region)
×
NEW
UNCOV
175

×
NEW
UNCOV
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