New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CLOUDP-237254: Update remaining commands to append deployment type telemetry #2803
Changes from all commits
7b03ca2
0f09787
f936057
12ba877
c41cdad
a5b8efc
a516a09
e20990e
d279d09
4fba73d
a6555e4
4d7100a
af4b72d
a27346a
0363088
a7c2c4b
494a136
7e108b0
4cfd79f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,12 +24,11 @@ import ( | |
"github.com/golang/mock/gomock" | ||
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli" | ||
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli/deployments/options" | ||
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/config" | ||
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli/deployments/test/fixture" | ||
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/flag" | ||
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/mocks" | ||
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/podman" | ||
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/pointer" | ||
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/store" | ||
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/test" | ||
"github.com/stretchr/testify/assert" | ||
"go.mongodb.org/atlas-sdk/v20231115008/admin" | ||
|
@@ -43,43 +42,20 @@ const ( | |
func TestRun_ConnectLocal(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
ctx := context.Background() | ||
mockPodman := mocks.NewMockClient(ctrl) | ||
buf := new(bytes.Buffer) | ||
|
||
deploymenTest := fixture.NewMockLocalDeploymentOpts(ctrl, expectedLocalDeployment) | ||
connectOpts := &options.ConnectOpts{ | ||
ConnectWith: "connectionString", | ||
DeploymentOpts: options.DeploymentOpts{ | ||
PodmanClient: mockPodman, | ||
DeploymentName: expectedLocalDeployment, | ||
DeploymentType: "local", | ||
}, | ||
ConnectWith: "connectionString", | ||
DeploymentOpts: *deploymenTest.Opts, | ||
OutputOpts: cli.OutputOpts{ | ||
OutWriter: buf, | ||
}, | ||
} | ||
|
||
expectedContainers := []*podman.Container{ | ||
{ | ||
Names: []string{expectedLocalDeployment}, | ||
State: "running", | ||
Labels: map[string]string{"version": "6.0.9"}, | ||
ID: expectedLocalDeployment, | ||
}, | ||
} | ||
|
||
mockPodman. | ||
EXPECT(). | ||
Ready(ctx). | ||
Return(nil). | ||
Times(1) | ||
deploymenTest.LocalMockFlow(ctx) | ||
|
||
mockPodman. | ||
EXPECT(). | ||
ListContainers(ctx, options.MongodHostnamePrefix). | ||
Return(expectedContainers, nil). | ||
Times(1) | ||
|
||
mockPodman. | ||
deploymenTest.MockPodman. | ||
EXPECT(). | ||
ContainerInspect(ctx, options.MongodHostnamePrefix+"-"+expectedLocalDeployment). | ||
Return([]*podman.InspectContainerData{ | ||
|
@@ -122,18 +98,12 @@ func TestRun_ConnectAtlas(t *testing.T) { | |
ctx := context.Background() | ||
buf := new(bytes.Buffer) | ||
|
||
mockAtlasClusterListStore := mocks.NewMockClusterLister(ctrl) | ||
mockCredentialsGetter := mocks.NewMockCredentialsGetter(ctrl) | ||
mockAtlasClusterDescriber := mocks.NewMockClusterDescriber(ctrl) | ||
deploymenTest := fixture.NewMockAtlasDeploymentOpts(ctrl, expectedAtlasDeployment) | ||
|
||
connectOpts := &options.ConnectOpts{ | ||
ConnectWith: "connectionString", | ||
DeploymentOpts: options.DeploymentOpts{ | ||
AtlasClusterListStore: mockAtlasClusterListStore, | ||
DeploymentName: expectedAtlasDeployment, | ||
DeploymentType: "atlas", | ||
CredStore: mockCredentialsGetter, | ||
}, | ||
ConnectWith: "connectionString", | ||
DeploymentOpts: *deploymenTest.Opts, | ||
ConnectToAtlasOpts: options.ConnectToAtlasOpts{ | ||
Store: mockAtlasClusterDescriber, | ||
GlobalOpts: cli.GlobalOpts{ | ||
|
@@ -161,29 +131,14 @@ func TestRun_ConnectAtlas(t *testing.T) { | |
}, | ||
} | ||
|
||
mockAtlasClusterListStore. | ||
EXPECT(). | ||
ProjectClusters(connectOpts.ProjectID, | ||
&store.ListOptions{ | ||
PageNum: cli.DefaultPage, | ||
ItemsPerPage: options.MaxItemsPerPage, | ||
}, | ||
). | ||
Return(expectedAtlasClusters, nil). | ||
Times(1) | ||
deploymenTest.CommonAtlasMocks(connectOpts.ProjectID) | ||
|
||
mockAtlasClusterDescriber. | ||
EXPECT(). | ||
AtlasCluster(connectOpts.ProjectID, expectedAtlasDeployment). | ||
Return(&expectedAtlasClusters.GetResults()[0], nil). | ||
Times(1) | ||
|
||
mockCredentialsGetter. | ||
EXPECT(). | ||
AuthType(). | ||
Return(config.OAuth). | ||
Times(1) | ||
|
||
if err := Run(ctx, connectOpts); err != nil { | ||
t.Fatalf("Run() unexpected error: %v", err) | ||
} | ||
|
@@ -192,6 +147,27 @@ func TestRun_ConnectAtlas(t *testing.T) { | |
`, buf.String()) | ||
} | ||
|
||
func TestPostRun(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
deploymentsTest := fixture.NewMockLocalDeploymentOpts(ctrl, "localDeployment") | ||
buf := new(bytes.Buffer) | ||
|
||
opts := &options.ConnectOpts{ | ||
DeploymentOpts: *deploymentsTest.Opts, | ||
OutputOpts: cli.OutputOpts{ | ||
OutWriter: buf, | ||
}, | ||
} | ||
|
||
deploymentsTest. | ||
MockDeploymentTelemetry. | ||
EXPECT(). | ||
AppendDeploymentType(). | ||
Times(1) | ||
|
||
PostRun(opts) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. given this test doesn't test much left a comment to get rid of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a way to future proof changes and making sure we always capture telemetry, with time maybe more values will be added here, but id'like to keep them tested There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. merging but feel free to pushback if there are any other reasons |
||
} | ||
|
||
func TestConnectBuilder(t *testing.T) { | ||
test.CmdValidator( | ||
t, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need it there so that we can test it