Skip to content

Commit 5903257

Browse files
CLOUDP-66571: add tests to profile (#229)
1 parent 5b8405f commit 5903257

File tree

116 files changed

+502
-29
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+502
-29
lines changed

.githooks/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ done
1010

1111
if [[ -n "${STAGED_GO_FILES}" ]]; then
1212
set -o errexit
13-
go test -race ./internal...
13+
go test --tags="unit integration" -race ./internal...
1414
make fix-lint
1515
set +o errexit
1616
fi

Makefile

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ VERSION=$(shell git describe --always --tags)
1212
LINKER_FLAGS=-X github.com/mongodb/mongocli/internal/version.Version=${VERSION}
1313

1414
TEST_CMD?=go test
15+
UNIT_TAGS?=unit
16+
INTEGRATION_TAGS?=integration
1517
E2E_TAGS?=e2e
1618
E2E_BINARY?=../../bin/${BINARY_NAME}
1719

@@ -35,9 +37,7 @@ fmt: ## Format code
3537
@scripts/fmt.sh
3638

3739
.PHONY: test
38-
test: ## Run tests
39-
@echo "==> Running tests..."
40-
${TEST_CMD} -race -cover -count=1 -coverprofile ${COVERAGE} ./internal...
40+
test: unit-test integration-test
4141

4242
.PHONY: lint
4343
lint: ## Run linter
@@ -72,6 +72,16 @@ e2e-test: build ## Run E2E tests
7272
# the target assumes the MCLI-* environment variables are exported
7373
${TEST_CMD} -v -p 1 -parallel 1 -timeout 15m -tags="${E2E_TAGS}" ./e2e...
7474

75+
.PHONY: integration-test
76+
integration-test: ## Run integration tests
77+
@echo "==> Running integration tests..."
78+
${TEST_CMD} --tags="${INTEGRATION_TAGS}" -count=1 ./internal...
79+
80+
.PHONY: unit-test
81+
unit-test: ## Run unit-tests
82+
@echo "==> Running unit tests..."
83+
${TEST_CMD} --tags="${UNIT_TAGS}" -race -cover -count=1 -coverprofile ${COVERAGE} ./internal...
84+
7585
.PHONY: install
7686
install: ## Install a binary in $GOPATH/bin
7787
@echo "==> Installing to $(INSTALL_PATH)"

build/ci/evergreen.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ tasks:
341341
commands:
342342
- func: "clone"
343343
- func: "build"
344-
- name: unit_test
344+
- name: test
345345
tags: ["code_health"]
346346
commands:
347347
- func: "clone"

cmd/mongocli/mongocli.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,21 +97,21 @@ func init() {
9797

9898
profile := rootCmd.PersistentFlags().StringP(flag.Profile, flag.ProfileShort, "", usage.Profile)
9999
cobra.OnInitialize(func() {
100-
initConfig(profile)
100+
initConfig(*profile)
101101
})
102102
}
103103

104104
// initConfig reads in config file and ENV variables if set.
105-
func initConfig(profileName *string) {
105+
func initConfig(profileName string) {
106106
if err := config.Load(); err != nil {
107107
log.Fatalf("Error loading config: %v", err)
108108
}
109109

110110
availableProfiles := config.List()
111-
if *profileName != "" {
111+
if profileName != "" {
112112
config.SetName(profileName)
113113
} else if len(availableProfiles) == 1 {
114-
config.SetName(&availableProfiles[0])
114+
config.SetName(availableProfiles[0])
115115
}
116116
}
117117

e2e/atlas/alert_settings_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14+
1415
// +build e2e atlas,generic
1516

1617
package atlas_test

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ require (
1919
github.com/spf13/jwalterweatherman v1.1.0 // indirect
2020
github.com/spf13/pflag v1.0.5 // indirect
2121
github.com/spf13/viper v1.7.0
22+
github.com/stretchr/testify v1.6.1
2223
go.mongodb.org/atlas v0.3.1-0.20200715182911-bdd98ee452e6
2324
go.mongodb.org/ops-manager v0.7.1-0.20200716111014-0e6b5a319279
2425
golang.org/x/crypto v0.0.0-20191108234033-bd318be0434a // indirect

internal/cli/agents/upgrade_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
// +build unit
16+
1517
package agents
1618

1719
import (

internal/cli/alerts/acknowledge_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
// +build unit
16+
1517
package alerts
1618

1719
import (

internal/cli/alerts/describe_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
// +build unit
16+
1517
package alerts
1618

1719
import (

internal/cli/alerts/global_list_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
// +build unit
16+
1517
package alerts
1618

1719
import (

0 commit comments

Comments
 (0)