Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions internal/cli/atlas/quickstart/quick_start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
)

func TestBuilder(t *testing.T) {
t.Cleanup(cleanUpConfig)
t.Cleanup(test.CleanupConfig)
test.CmdValidator(
t,
Builder(),
Expand All @@ -45,7 +45,7 @@ func TestBuilder(t *testing.T) {
}

func TestQuickstartOpts_Run(t *testing.T) {
t.Cleanup(cleanUpConfig)
t.Cleanup(test.CleanupConfig)
ctrl := gomock.NewController(t)
mockStore := mocks.NewMockAtlasClusterQuickStarter(ctrl)
defer ctrl.Finish()
Expand Down Expand Up @@ -104,7 +104,7 @@ func TestQuickstartOpts_Run(t *testing.T) {
}

func TestQuickstartOpts_Run_NotLoggedIn(t *testing.T) {
t.Cleanup(cleanUpConfig)
t.Cleanup(test.CleanupConfig)
ctrl := gomock.NewController(t)
mockStore := mocks.NewMockAtlasClusterQuickStarter(ctrl)
defer ctrl.Finish()
Expand All @@ -128,7 +128,7 @@ func TestQuickstartOpts_Run_NotLoggedIn(t *testing.T) {
}

func TestQuickstartOpts_Run_NeedLogin_ForceAfterLogin(t *testing.T) {
t.Cleanup(cleanUpConfig)
t.Cleanup(test.CleanupConfig)
ctrl := gomock.NewController(t)
mockStore := mocks.NewMockAtlasClusterQuickStarter(ctrl)
mockLoginFlow := mocks.NewMockLoginFlow(ctrl)
Expand Down Expand Up @@ -219,9 +219,3 @@ func setConfig() func(ctx context.Context) error {
return nil
}
}

func cleanUpConfig() {
config.SetAccessToken("")
config.SetPublicAPIKey("")
config.SetPrivateAPIKey("")
}
14 changes: 4 additions & 10 deletions internal/cli/atlas/setup/setup_cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
)

func TestBuilder(t *testing.T) {
t.Cleanup(cleanUpConfig)
t.Cleanup(test.CleanupConfig)
test.CmdValidator(
t,
Builder(),
Expand All @@ -43,7 +43,7 @@ func TestBuilder(t *testing.T) {
}

func Test_setupOpts_Run(t *testing.T) {
t.Cleanup(cleanUpConfig)
t.Cleanup(test.CleanupConfig)
ctrl := gomock.NewController(t)
mockRegFlow := mocks.NewMockRegisterFlow(ctrl)
mockQuickstartFlow := mocks.NewMockFlow(ctrl)
Expand Down Expand Up @@ -82,7 +82,7 @@ func Test_setupOpts_Run(t *testing.T) {
}

func Test_setupOpts_RunWithAPIKeys(t *testing.T) {
t.Cleanup(cleanUpConfig)
t.Cleanup(test.CleanupConfig)
ctrl := gomock.NewController(t)
mockRegFlow := mocks.NewMockRegisterFlow(ctrl)
mockQuickstartFlow := mocks.NewMockFlow(ctrl)
Expand Down Expand Up @@ -123,7 +123,7 @@ Run "atlas auth setup --profile <profile_name>" to create a new Atlas account on
}

func Test_setupOpts_RunSkipRegister(t *testing.T) {
t.Cleanup(cleanUpConfig)
t.Cleanup(test.CleanupConfig)
ctrl := gomock.NewController(t)
mockRegFlow := mocks.NewMockRegisterFlow(ctrl)
mockQuickstartFlow := mocks.NewMockFlow(ctrl)
Expand Down Expand Up @@ -174,9 +174,3 @@ func setConfig() func(ctx context.Context) error {
return nil
}
}

func cleanUpConfig() {
config.SetAccessToken("")
config.SetPublicAPIKey("")
config.SetPrivateAPIKey("")
}
2 changes: 2 additions & 0 deletions internal/cli/auth/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,15 @@ Successfully logged in as test@10gen.com.
}

func TestLoginPreRun(t *testing.T) {
t.Cleanup(test.CleanupConfig)
ctx := context.TODO()
config.SetPublicAPIKey("public")
config.SetPrivateAPIKey("private")
require.ErrorContains(t, loginPreRun(ctx), fmt.Sprintf(AlreadyAuthenticatedError, "public"), LoginWithProfileMsg)
}

func Test_loginOpts_oauthFlow(t *testing.T) {
t.Cleanup(test.CleanupConfig)
t.Run("updates accessToken and refreshToken after code is verified", func(t *testing.T) {
ctrl := gomock.NewController(t)
mockFlow := mocks.NewMockAuthenticator(ctrl)
Expand Down
6 changes: 3 additions & 3 deletions internal/cli/auth/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
)

func TestRegisterBuilder(t *testing.T) {
t.Cleanup(cleanUpConfig)
t.Cleanup(test.CleanupConfig)
test.CmdValidator(
t,
RegisterBuilder(),
Expand All @@ -44,7 +44,7 @@ func TestRegisterBuilder(t *testing.T) {
}

func Test_registerOpts_Run(t *testing.T) {
t.Cleanup(cleanUpConfig)
t.Cleanup(test.CleanupConfig)
ctrl := gomock.NewController(t)
mockFlow := mocks.NewMockAuthenticator(ctrl)
mockRegisterFlow := &registerAuthenticator{
Expand Down Expand Up @@ -131,7 +131,7 @@ Successfully logged in as test@10gen.com.
}

func TestRegisterPreRun(t *testing.T) {
t.Cleanup(cleanUpConfig)
t.Cleanup(test.CleanupConfig)
config.SetPublicAPIKey("public")
config.SetPrivateAPIKey("private")
require.ErrorContains(t, registerPreRun(), fmt.Sprintf(AlreadyAuthenticatedError, "public"), WithProfileMsg)
Expand Down
14 changes: 14 additions & 0 deletions internal/cli/auth/status.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2022 MongoDB Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.package auth

package auth

import (
Expand Down
13 changes: 4 additions & 9 deletions internal/cli/auth/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (
"testing"

"github.com/mongodb/mongodb-atlas-cli/internal/config"
"github.com/mongodb/mongodb-atlas-cli/internal/test"
"github.com/stretchr/testify/assert"
)

func Test_GetStatus_InvalidToken(t *testing.T) {
t.Cleanup(cleanUpConfig)
t.Cleanup(test.CleanupConfig)
ctx := context.TODO()
config.SetAccessToken("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ")

Expand All @@ -18,7 +19,7 @@ func Test_GetStatus_InvalidToken(t *testing.T) {
}

func Test_GetStatus_APIKeys(t *testing.T) {
t.Cleanup(cleanUpConfig)
t.Cleanup(test.CleanupConfig)
ctx := context.TODO()

config.SetPublicAPIKey("publicKey")
Expand All @@ -29,15 +30,9 @@ func Test_GetStatus_APIKeys(t *testing.T) {
}

func Test_GetStatus_NotLoggedIn(t *testing.T) {
t.Cleanup(cleanUpConfig)
t.Cleanup(test.CleanupConfig)
ctx := context.TODO()

status, _ := GetStatus(ctx)
assert.Equal(t, NotLoggedIn, status)
}

func cleanUpConfig() {
config.SetAccessToken("")
config.SetPublicAPIKey("")
config.SetPrivateAPIKey("")
}
24 changes: 24 additions & 0 deletions internal/telemetry/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ import (

"github.com/mongodb/mongodb-atlas-cli/internal/config"
"github.com/mongodb/mongodb-atlas-cli/internal/flag"
"github.com/mongodb/mongodb-atlas-cli/internal/test"
"github.com/mongodb/mongodb-atlas-cli/internal/version"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
)

func TestWithCommandPath(t *testing.T) {
t.Cleanup(test.CleanupConfig)
config.ToolName = config.AtlasCLI
testCmd := &cobra.Command{
Use: "test",
Expand All @@ -44,6 +46,7 @@ func TestWithCommandPath(t *testing.T) {
}

func TestWithCommandPathAndAlias(t *testing.T) {
t.Cleanup(test.CleanupConfig)
config.ToolName = config.AtlasCLI
rootCmd := &cobra.Command{
Use: "root",
Expand All @@ -63,6 +66,7 @@ func TestWithCommandPathAndAlias(t *testing.T) {
}

func TestWithProfileDefault(t *testing.T) {
t.Cleanup(test.CleanupConfig)
config.ToolName = config.AtlasCLI

e := newEvent(withProfile())
Expand All @@ -72,6 +76,7 @@ func TestWithProfileDefault(t *testing.T) {
}

func TestWithProfileCustom(t *testing.T) {
t.Cleanup(test.CleanupConfig)
config.ToolName = config.AtlasCLI

const profile = "test"
Expand All @@ -85,6 +90,7 @@ func TestWithProfileCustom(t *testing.T) {
}

func TestWithDuration(t *testing.T) {
t.Cleanup(test.CleanupConfig)
config.ToolName = config.AtlasCLI

cmd := &cobra.Command{
Expand All @@ -102,6 +108,7 @@ func TestWithDuration(t *testing.T) {
}

func TestWithFlags(t *testing.T) {
t.Cleanup(test.CleanupConfig)
config.ToolName = config.AtlasCLI

cmd := &cobra.Command{
Expand All @@ -122,6 +129,7 @@ func TestWithFlags(t *testing.T) {
}

func TestWithVersion(t *testing.T) {
t.Cleanup(test.CleanupConfig)
config.ToolName = config.AtlasCLI

version.Version = "vTest"
Expand All @@ -135,6 +143,7 @@ func TestWithVersion(t *testing.T) {
}

func TestWithOS(t *testing.T) {
t.Cleanup(test.CleanupConfig)
config.ToolName = config.AtlasCLI

e := newEvent(withOS())
Expand All @@ -145,6 +154,7 @@ func TestWithOS(t *testing.T) {
}

func TestWithAuthMethod_apiKey(t *testing.T) {
t.Cleanup(test.CleanupConfig)
config.ToolName = config.AtlasCLI

config.SetPublicAPIKey("test-public")
Expand All @@ -157,6 +167,7 @@ func TestWithAuthMethod_apiKey(t *testing.T) {
}

func TestWithAuthMethod_oauth(t *testing.T) {
t.Cleanup(test.CleanupConfig)
config.ToolName = config.AtlasCLI

config.SetPublicAPIKey("")
Expand All @@ -169,6 +180,7 @@ func TestWithAuthMethod_oauth(t *testing.T) {
}

func TestWithService(t *testing.T) {
t.Cleanup(test.CleanupConfig)
config.ToolName = config.AtlasCLI

const url = "http://host.test"
Expand All @@ -183,6 +195,7 @@ func TestWithService(t *testing.T) {
}

func TestWithProjectID_Flag(t *testing.T) {
t.Cleanup(test.CleanupConfig)
config.ToolName = config.AtlasCLI

cmd := &cobra.Command{
Expand All @@ -205,6 +218,7 @@ func TestWithProjectID_Flag(t *testing.T) {
}

func TestWithProjectID_Config(t *testing.T) {
t.Cleanup(test.CleanupConfig)
config.ToolName = config.AtlasCLI

cmd := &cobra.Command{
Expand All @@ -227,6 +241,7 @@ func TestWithProjectID_Config(t *testing.T) {
}

func TestWithProjectID_NoFlagOrConfig(t *testing.T) {
t.Cleanup(test.CleanupConfig)
config.ToolName = config.AtlasCLI

cmd := &cobra.Command{
Expand All @@ -247,6 +262,7 @@ func TestWithProjectID_NoFlagOrConfig(t *testing.T) {
}

func TestWithOrgID_Flag(t *testing.T) {
t.Cleanup(test.CleanupConfig)
config.ToolName = config.AtlasCLI

cmd := &cobra.Command{
Expand All @@ -269,6 +285,7 @@ func TestWithOrgID_Flag(t *testing.T) {
}

func TestWithOrgID_Config(t *testing.T) {
t.Cleanup(test.CleanupConfig)
config.ToolName = config.AtlasCLI

cmd := &cobra.Command{
Expand All @@ -291,6 +308,7 @@ func TestWithOrgID_Config(t *testing.T) {
}

func TestWithOrgID_NoFlagOrConfig(t *testing.T) {
t.Cleanup(test.CleanupConfig)
config.ToolName = config.AtlasCLI

cmd := &cobra.Command{
Expand All @@ -311,6 +329,7 @@ func TestWithOrgID_NoFlagOrConfig(t *testing.T) {
}

func TestWithError(t *testing.T) {
t.Cleanup(test.CleanupConfig)
config.ToolName = config.AtlasCLI

e := newEvent(withError(errors.New("test")))
Expand All @@ -321,6 +340,7 @@ func TestWithError(t *testing.T) {
}

func TestWithExtraProps(t *testing.T) {
t.Cleanup(test.CleanupConfig)
config.ToolName = config.AtlasCLI

e := newEvent(withExtraProps(map[string]interface{}{"a": true}))
Expand Down Expand Up @@ -380,6 +400,7 @@ func TestSanitizeSelectOption(t *testing.T) {
}

func TestWithPrompt(t *testing.T) {
t.Cleanup(test.CleanupConfig)
config.ToolName = config.AtlasCLI

q := "random question"
Expand All @@ -393,6 +414,7 @@ func TestWithPrompt(t *testing.T) {
}

func TestWithChoice(t *testing.T) {
t.Cleanup(test.CleanupConfig)
config.ToolName = config.AtlasCLI

c := "test choice"
Expand All @@ -404,6 +426,7 @@ func TestWithChoice(t *testing.T) {
}

func TestWithDefault(t *testing.T) {
t.Cleanup(test.CleanupConfig)
config.ToolName = config.AtlasCLI

q := true
Expand All @@ -415,6 +438,7 @@ func TestWithDefault(t *testing.T) {
}

func TestWithEmpty(t *testing.T) {
t.Cleanup(test.CleanupConfig)
config.ToolName = config.AtlasCLI

q := true
Expand Down
Loading