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

mongodb / mongodb-atlas-cli / 26228926989

21 May 2026 01:27PM UTC coverage: 22.63% (-41.6%) from 64.198%
26228926989

push

github

apix-bot[bot]
Update compliance report for v1.55.0

8987 of 39713 relevant lines covered (22.63%)

0.25 hits per line

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

10.26
/internal/cli/clusters/load_sample_data.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/store"
25
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/usage"
26
        "github.com/spf13/cobra"
27
        atlasv2 "go.mongodb.org/atlas-sdk/v20250312018/admin"
28
)
29

30
//go:generate go tool go.uber.org/mock/mockgen -typed -destination=load_sample_data_mock_test.go -package=clusters -source=load_sample_data.go
31

32
type SampleDataAdder interface {
33
        AddSampleData(string, string) (*atlasv2.SampleDatasetStatus, error)
34
}
35

36
type LoadSampleDataOpts struct {
37
        cli.ProjectOpts
38
        cli.OutputOpts
39
        name  string
40
        store SampleDataAdder
41
}
42

43
func (opts *LoadSampleDataOpts) initStore(ctx context.Context) func() error {
×
44
        return func() error {
×
45
                var err error
×
46
                opts.store, err = store.New(store.AuthenticatedPreset(config.Default()), store.WithContext(ctx))
×
47
                return err
×
48
        }
×
49
}
50

51
var addTmpl = "Sample data load job {{.Id}} created.\n"
52

53
func (opts *LoadSampleDataOpts) Run() error {
1✔
54
        r, err := opts.store.AddSampleData(opts.ConfigProjectID(), opts.name)
1✔
55
        if err != nil {
1✔
56
                return err
×
57
        }
×
58

59
        return opts.Print(r)
1✔
60
}
61

62
// atlas cluster loadSampleData <clusterName> --projectId projectId -o json.
63
func LoadSampleDataBuilder() *cobra.Command {
×
64
        opts := &LoadSampleDataOpts{}
×
65
        cmd := &cobra.Command{
×
66
                Use:        "loadSampleData <clusterName>",
×
67
                Short:      "Load sample data into the specified cluster for your project.",
×
68
                Long:       fmt.Sprintf(usage.RequiredRole, "Project Owner"),
×
69
                Deprecated: "use 'atlas clusters sampleData load' instead",
×
70
                Args:       require.ExactArgs(1),
×
71
                Annotations: map[string]string{
×
72
                        "clusterNameDesc": "Label that identifies the cluster that you want to load sample data into.",
×
73
                        "output":          addTmpl,
×
74
                },
×
75
                PreRunE: func(cmd *cobra.Command, _ []string) error {
×
76
                        return opts.PreRunE(
×
77
                                opts.ValidateProjectID,
×
78
                                opts.initStore(cmd.Context()),
×
79
                                opts.InitOutput(cmd.OutOrStdout(), addTmpl),
×
80
                        )
×
81
                },
×
82
                RunE: func(_ *cobra.Command, args []string) error {
×
83
                        opts.name = args[0]
×
84
                        return opts.Run()
×
85
                },
×
86
        }
87

88
        opts.AddProjectOptsFlags(cmd)
×
89
        opts.AddOutputOptFlags(cmd)
×
90

×
91
        return cmd
×
92
}
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