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

mongodb / mongodb-atlas-cli / 16670310313

01 Aug 2025 08:29AM UTC coverage: 57.953% (-7.1%) from 65.017%
16670310313

Pull #4071

github

fmenezes
lint
Pull Request #4071: chore: remove unit tag from tests

23613 of 40745 relevant lines covered (57.95%)

2.74 hits per line

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

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

30
//go:generate go tool go.uber.org/mock/mockgen -typed -destination=load_sample_data_mock_test.go -package=clusters . SampleDataAdder
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 {
×
54
        r, err := opts.store.AddSampleData(opts.ConfigProjectID(), opts.name)
×
55
        if err != nil {
×
56
                return err
×
57
        }
×
58

59
        return opts.Print(r)
×
60
}
61

62
// atlas cluster loadSampleData <clusterName> --projectId projectId -o json.
63
func LoadSampleDataBuilder() *cobra.Command {
1✔
64
        opts := &LoadSampleDataOpts{}
1✔
65
        cmd := &cobra.Command{
1✔
66
                Use:        "loadSampleData <clusterName>",
1✔
67
                Short:      "Load sample data into the specified cluster for your project.",
1✔
68
                Long:       fmt.Sprintf(usage.RequiredRole, "Project Owner"),
1✔
69
                Deprecated: "use 'atlas clusters sampleData load' instead",
1✔
70
                Args:       require.ExactArgs(1),
1✔
71
                Annotations: map[string]string{
1✔
72
                        "clusterNameDesc": "Label that identifies the cluster that you want to load sample data into.",
1✔
73
                        "output":          addTmpl,
1✔
74
                },
1✔
75
                PreRunE: func(cmd *cobra.Command, _ []string) error {
1✔
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)
1✔
89
        opts.AddOutputOptFlags(cmd)
1✔
90

1✔
91
        return cmd
1✔
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