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

mongodb / mongodb-atlas-cli / 16654685320

31 Jul 2025 04:31PM UTC coverage: 65.017% (-0.08%) from 65.098%
16654685320

Pull #4057

github

Waybo26
Merge branch 'master' into CLOUDP-333877
Pull Request #4057: CLOUDP-333877: create streams workspaces atlas cli command + workspaces create

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

41 existing lines in 1 file now uncovered.

26491 of 40745 relevant lines covered (65.02%)

3.11 hits per line

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

59.41
/internal/cli/streams/instance/create.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=create_mock_test.go -package=instance . StreamsCreator
32

33
type StreamsCreator interface {
34
        CreateStream(string, *atlasv2.StreamsTenant) (*atlasv2.StreamsTenant, error)
35
}
36

37
type CreateOpts 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       StreamsCreator
48
}
49

50
const (
51
        createTemplate  = "Atlas Streams Processor Instance '{{.Name}}' successfully created.\n"
52
        createWorkspace = "Atlas Streams Processor Workspace '{{.Name}}' successfully created.\n"
53
        defaultTier     = "SP30"
54
)
55

56
func (opts *CreateOpts) Run() error {
3✔
57
        streamProcessor := atlasv2.NewStreamsTenant()
3✔
58
        streamProcessor.Name = &opts.name
3✔
59
        streamProcessor.GroupId = &opts.ProjectID
3✔
60
        streamProcessor.DataProcessRegion = atlasv2.NewStreamsDataProcessRegion(opts.provider, opts.region)
3✔
61

3✔
62
        tierOrDefault := defaultTier
3✔
63
        if opts.tier != "" {
6✔
64
                tierOrDefault = opts.tier
3✔
65
        }
3✔
66
        streamConfig := streamProcessor.GetStreamConfig()
3✔
67
        streamConfig.Tier = &tierOrDefault
3✔
68
        streamProcessor.StreamConfig = &streamConfig
3✔
69

3✔
70
        r, err := opts.store.CreateStream(opts.ProjectID, streamProcessor)
3✔
71

3✔
72
        if err != nil {
3✔
UNCOV
73
                return err
×
UNCOV
74
        }
×
75

76
        return opts.Print(r)
3✔
77
}
78

79
func (opts *CreateOpts) initStore(ctx context.Context) func() error {
1✔
80
        return func() error {
2✔
81
                var err error
1✔
82
                opts.store, err = store.New(store.AuthenticatedPreset(config.Default()), store.WithContext(ctx))
1✔
83
                return err
1✔
84
        }
1✔
85
}
86

87
// CreateBuilder
88
// atlas streams instance create [name]
89
// --provider AWS
90
// --region VIRGINIA_USA.
91
func CreateBuilder() *cobra.Command {
1✔
92
        opts := &CreateOpts{}
1✔
93
        cmd := &cobra.Command{
1✔
94
                Use:   "create <name>",
1✔
95
                Short: "Create an Atlas Stream Processing instance for your project",
1✔
96
                Long:  `To get started quickly, specify a name, a cloud provider, and a region to configure an Atlas Stream Processing instance.` + fmt.Sprintf(usage.RequiredRole, "Project Owner"),
1✔
97
                Example: `  # Deploy an Atlas Stream Processing instance called myProcessor for the project with the ID 5e2211c17a3e5a48f5497de3:
1✔
98
  atlas streams instance create myProcessor --projectId 5e2211c17a3e5a48f5497de3 --provider AWS --region VIRGINIA_USA --tier SP30`,
1✔
99
                Args: require.ExactArgs(1),
1✔
100
                Annotations: map[string]string{
1✔
101
                        "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✔
102
                        "output":   createTemplate,
1✔
103
                },
1✔
104
                PreRunE: func(cmd *cobra.Command, args []string) error {
2✔
105
                        opts.name = args[0]
1✔
106
                        return opts.PreRunE(
1✔
107
                                opts.ValidateProjectID,
1✔
108
                                opts.initStore(cmd.Context()),
1✔
109
                                opts.InitOutput(cmd.OutOrStdout(), createTemplate),
1✔
110
                        )
1✔
111
                },
1✔
112
                RunE: func(_ *cobra.Command, _ []string) error {
1✔
113
                        return opts.Run()
1✔
114
                },
1✔
115
        }
116

117
        cmd.Flags().StringVar(&opts.provider, flag.Provider, "AWS", usage.StreamsProvider)
1✔
118
        cmd.Flags().StringVarP(&opts.region, flag.Region, flag.RegionShort, "", usage.StreamsRegion)
1✔
119

1✔
120
        opts.AddProjectOptsFlags(cmd)
1✔
121
        opts.AddOutputOptFlags(cmd)
1✔
122

1✔
123
        cmd.Flags().StringVar(&opts.tier, flag.Tier, "SP30", usage.StreamsInstanceTier)
1✔
124

1✔
125
        _ = cmd.MarkFlagRequired(flag.Provider)
1✔
126
        _ = cmd.MarkFlagRequired(flag.Region)
1✔
127

1✔
128
        return cmd
1✔
129
}
130

NEW
UNCOV
131
func WorkspaceCreateBuilder() *cobra.Command {
×
NEW
UNCOV
132
        opts := &CreateOpts{}
×
NEW
UNCOV
133
        cmd := &cobra.Command{
×
NEW
UNCOV
134
                Use:   "create <name>",
×
NEW
UNCOV
135
                Short: "Create an Atlas Stream Processing workspace for your project",
×
NEW
UNCOV
136
                Long:  `To get started quickly, specify a name, a cloud provider, and a region to configure an Atlas Stream Processing workspace.` + fmt.Sprintf(usage.RequiredRole, "Project Owner"),
×
NEW
UNCOV
137
                Example: `  # Deploy an Atlas Stream Processing workspace called myProcessor for the project with the ID 5e2211c17a3e5a48f5497de3:
×
NEW
UNCOV
138
  atlas streams instance create myProcessor --projectId 5e2211c17a3e5a48f5497de3 --provider AWS --region VIRGINIA_USA --tier SP10 --defaultTier SP30 --maxTierSize SP50`,
×
NEW
UNCOV
139
                Args: require.ExactArgs(1),
×
NEW
UNCOV
140
                Annotations: map[string]string{
×
NEW
UNCOV
141
                        "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
142
                        "output":   createWorkspace,
×
NEW
UNCOV
143
                },
×
NEW
UNCOV
144
                PreRunE: func(cmd *cobra.Command, args []string) error {
×
NEW
UNCOV
145
                        opts.name = args[0]
×
NEW
UNCOV
146

×
NEW
UNCOV
147
                        return opts.PreRunE(
×
NEW
UNCOV
148
                                opts.ValidateProjectID,
×
NEW
UNCOV
149
                                opts.initStore(cmd.Context()),
×
NEW
UNCOV
150
                                opts.InitOutput(cmd.OutOrStdout(), createWorkspace),
×
NEW
UNCOV
151
                        )
×
NEW
UNCOV
152
                },
×
NEW
UNCOV
153
                RunE: func(_ *cobra.Command, _ []string) error {
×
NEW
UNCOV
154
                        return opts.Run()
×
NEW
UNCOV
155
                },
×
156
        }
157

NEW
UNCOV
158
        cmd.Flags().StringVar(&opts.provider, flag.Provider, "AWS", usage.StreamsProvider)
×
NEW
UNCOV
159
        cmd.Flags().StringVarP(&opts.region, flag.Region, flag.RegionShort, "", usage.StreamsRegion)
×
NEW
UNCOV
160

×
NEW
UNCOV
161
        opts.AddProjectOptsFlags(cmd)
×
NEW
UNCOV
162
        opts.AddOutputOptFlags(cmd)
×
NEW
UNCOV
163

×
NEW
UNCOV
164
        cmd.Flags().StringVar(&opts.tier, flag.Tier, "SP30", usage.StreamsWorkspaceTier)
×
NEW
UNCOV
165
        cmd.Flags().StringVar(&opts.defaultTier, flag.DefaultTier, "", usage.StreamsWorkspaceDefaultTier)
×
NEW
UNCOV
166
        cmd.Flags().StringVar(&opts.maxTierSize, flag.MaxTierSize, "", usage.StreamsWorkspaceMaxTierSize)
×
NEW
UNCOV
167

×
NEW
UNCOV
168
        _ = cmd.MarkFlagRequired(flag.Provider)
×
NEW
UNCOV
169
        _ = cmd.MarkFlagRequired(flag.Region)
×
NEW
UNCOV
170

×
NEW
UNCOV
171
        return cmd
×
172
}
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