Skip to content

fix: isolate test environment from external variables#613

Open
robertolopezlopez wants to merge 3 commits into
mainfrom
fix/unit_test_env_coupled
Open

fix: isolate test environment from external variables#613
robertolopezlopez wants to merge 3 commits into
mainfrom
fix/unit_test_env_coupled

Conversation

@robertolopezlopez
Copy link
Copy Markdown
Contributor

Description

This PR adds an extendable mechanism to ignore environment variables in unit tests.

Checklist

  • Tests added and all succeed (make test)
  • Regenerated mocks, etc. (make generate)
  • Linted (make lint)
  • Test your changes work for the CLI
    1. Clone / pull the latest CLI main.
    2. Run go get github.com/snyk/go-application-framework@YOUR_LATEST_GAF_COMMIT in the cliv2 directory.
      • Tip: for local testing, you can uncomment the line near the bottom of the CLI's go.mod to point to your local GAF code.
    3. Run go mod tidy in the cliv2 directory.
    4. Run the CLI tests and do any required manual testing.
    5. Open a PR in the CLI repo now with the go.mod and go.sum changes.
    • Once this PR is merged, repeat these steps, but pointing to the latest GAF commit on main and update your CLI PR.

@snyk-io
Copy link
Copy Markdown

snyk-io Bot commented May 22, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@snyk-io
Copy link
Copy Markdown

snyk-io Bot commented May 22, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@robertolopezlopez robertolopezlopez marked this pull request as ready for review May 26, 2026 08:00
@robertolopezlopez robertolopezlopez requested review from a team as code owners May 26, 2026 08:00
@snyk-pr-review-bot
Copy link
Copy Markdown

PR Reviewer Guide 🔍

🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected
📚 Repository Context Analyzed

This review considered 4 relevant code sections from 4 files (average relevance: 0.89)

Comment thread pkg/configtest/env.go
Comment on lines +5 to +12
// snykAPIKey is the AutomaticEnv name for configuration.API_URL (viper key "snyk_api").
// Keep aligned with pkg/configuration/constants.go.
const snykAPIKey = "SNYK_API"

// KnownLeakEnvironmentKeys is cleared when [IsolateEnvironmentForTest] is called with no arguments.
var KnownLeakEnvironmentKeys = []string{
snykAPIKey,
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you can use the value from pkg/configuration/constants.go directly here

Comment thread pkg/configtest/env.go
Comment on lines +22 to +27
for _, k := range toClear {
if k == "" {
continue
}
t.Setenv(k, "")
}
Copy link
Copy Markdown
Contributor

@danskmt danskmt May 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should consider if is lowercase / uppercase?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants