Skip to content
This repository was archived by the owner on Jul 15, 2023. It is now read-only.
This repository was archived by the owner on Jul 15, 2023. It is now read-only.

go.testEnvVars should override go.testEnvFile #2398

Description

I haven't found docs around usage of go.testEnvFile and go.testEnvVars,
but I instinctively expected them to behave similarly to how env and envFile work in launch.js: Variables are loaded from .env, but if explicitly set by testEnvVars, this value will prevail over .env value

https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_load-environment-variables-from-external-file-node

Any environment variable specified in the env dictionary will override variables loaded from the file.

To Reproduce

# .env
FOO=1
BAR=2
# .vscode/settings.json
{
    "go.testEnvFile": "${workspaceFolder}/.env",
    "go.testEnvVars": {
        "FOO": "BACON",
        "BAR": "EGGS",
    },
    "go.testFlags": ["-v"]
}

main_test.go

package main

import (
	"fmt"
	"os"
	"testing"
)

func TestEnvVar(t *testing.T) {
	foo := os.Getenv("FOO")
	bar := os.Getenv("BAR")
	fmt.Printf("foo: %v \n", foo)
	fmt.Printf("bar: %v \n", bar)

}

Result

=== RUN   TestEnvVar
foo: 1 
bar: 2 
--- PASS: TestEnvVar (0.00s)
PASS
ok  	github.com/weconnect/playground	(cached)
Success: Tests passed.
  • Click Run Test in vscode
  • Expected: FOO and BAR = "BACON" and "EGGS"
  • Got: FOO and BAR = "1" and "2"

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions