Skip to content

Commit c6f3c8d

Browse files
authored
chore: auto set test vars (#4115)
1 parent 34da433 commit c6f3c8d

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ To debug e2e tests.
117117

118118
Update e2e profiles by running `make add-e2e-profiles`.
119119

120-
Add needed env vars by:
120+
Add optional env vars by:
121121

122122
```shell
123123
touch .vscode/settings.json
@@ -129,8 +129,6 @@ Review and replace the atlas settings.
129129
```json
130130
{
131131
"go.testEnvVars": {
132-
"ATLAS_E2E_BINARY": "${workspaceFolder}/bin/atlas", // required
133-
"SNAPSHOTS_DIR": "${workspaceFolder}/test/e2e/testdata/.snapshots", // required
134132
"TEST_MODE": "live", // optional default is 'live'
135133
"GOCOVERDIR": "${workspaceFolder}/cov", // optional used for coverage counting
136134
"MONGODB_ATLAS_SKIP_UPDATE_CHECK": "yes", // optional but recommended

Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ ATLAS_INSTALL_PATH="${GOPATH}/bin/$(ATLAS_BINARY_NAME)"
1919

2020
LOCALDEV_IMAGE?=docker.io/mongodb/mongodb-atlas-local
2121
LINKER_FLAGS=-s -w -X github.com/mongodb/mongodb-atlas-cli/atlascli/internal/version.GitCommit=${GIT_SHA} -X github.com/mongodb/mongodb-atlas-cli/atlascli/internal/version.Version=${ATLAS_VERSION} -X github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli/deployments/options.LocalDevImage=${LOCALDEV_IMAGE}
22-
ATLAS_E2E_BINARY?=$(abspath bin/${ATLAS_BINARY_NAME})
23-
export SNAPSHOTS_DIR?=$(abspath test/e2e/testdata/.snapshots)
2422

2523
DEBUG_FLAGS=all=-N -l
2624

@@ -39,7 +37,6 @@ endif
3937
export TERM := linux-m
4038
export GO111MODULE := on
4139
export GOTOOLCHAIN := local
42-
export ATLAS_E2E_BINARY
4340

4441
.PHONY: pre-commit
4542
pre-commit: ## Run pre-commit hook

test/internal/atlas_e2e_test_generator.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232
"os"
3333
"os/exec"
3434
"path"
35-
"path/filepath"
3635
"regexp"
3736
"slices"
3837
"strconv"
@@ -460,15 +459,12 @@ func (g *AtlasE2ETestGenerator) RunCommand(args ...string) ([]byte, error) {
460459
func (g *AtlasE2ETestGenerator) snapshotBaseDir() string {
461460
g.t.Helper()
462461

463-
if os.Getenv("SNAPSHOTS_DIR") == "" {
464-
g.t.Fatal("missing env var SNAPSHOTS_DIR")
465-
}
466-
dir, err := filepath.Abs(os.Getenv("SNAPSHOTS_DIR"))
462+
snapshotsDir, err := snapshotBasePath()
467463
if err != nil {
468464
g.t.Fatal(err)
469465
}
470466

471-
return dir
467+
return snapshotsDir
472468
}
473469

474470
func (g *AtlasE2ETestGenerator) snapshotDir() string {

test/internal/env.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,32 @@ func GCPCredentials() (string, error) {
154154
return credentials, nil
155155
}
156156

157+
func repoPath() (string, error) {
158+
wd, err := os.Getwd()
159+
if err != nil {
160+
return "", err
161+
}
162+
163+
parts := strings.Split(wd, "/test/")
164+
165+
return parts[0], nil
166+
}
167+
157168
func AtlasCLIBin() (string, error) {
158-
path := os.Getenv("ATLAS_E2E_BINARY")
159-
cliPath, err := filepath.Abs(path)
169+
repo, err := repoPath()
160170
if err != nil {
161-
return "", fmt.Errorf("%w: invalid bin path %q", err, path)
171+
return "", err
162172
}
163173

164-
if _, err := os.Stat(cliPath); err != nil {
165-
return "", fmt.Errorf("%w: invalid bin %q", err, path)
174+
return filepath.Join(repo, "bin", "atlas"), nil
175+
}
176+
177+
func snapshotBasePath() (string, error) {
178+
repo, err := repoPath()
179+
if err != nil {
180+
return "", err
166181
}
167-
return cliPath, nil
182+
return filepath.Join(repo, "test", "e2e", "testdata", ".snapshots"), nil
168183
}
169184

170185
func ProfileData() (map[string]string, error) {

0 commit comments

Comments
 (0)