Cant set default environment variables in Goland Run/Debug configs
Does anyone know how to set default env variable like FUNCTIONAL=1 in goland IDE so that I can run functional tests from IDE.. I see an option called ‘defaults’ -> Go test -> Env variables.. but setting there doesnt seem to have any effect
Please sign in to leave a comment.
Hi Prathap,
How do you create the tests after that? And what IDE version do you have?
Can you please that the Default Run Configuration looks like this (see below) when configured?
Thank you.
Hi @Florin.
I have the same problem.
But the config env's are seted on one terminal.
$ export FOO=bar
and when i build with Run/Debug Configurations, the value is empty, but ...
when i run with
$ go run main.go
the variable is bar //correct
any ideas?
goland 2019.2
@Ricoterox your problem is a different one.
If you set the variable in a terminal inside the IDE, those won't be automatically sent to the run configurations.
You have to use the way mentioned above to set environment variables. Go to Run | Edit Configurations... | Templates | Go Build and set the environment variables there. Then all new run configurations will inherit those.
If you wish to set the variables for the terminal specifically, then go to Settings/Preferences | Tools | Terminal | Environment Variables. Note: the environment variables set here will only affect the GoLand terminal after it's closed and started again. And they will not affect the Run Configurations.
If you still have issues, please let me know.
Thank you Florin
i see what the problem was.
But i came up with another solution.
I create a makefile with a run target.
run:
@echo "Running main.go"
GOPATH=$(GOPATH) go run $(GOFILES)
this works perfectly with my problem.
But then I ended up using an .env file with all those keys.
Best,
Danny
Hi Danny. That doesn't look like a solution, but if it works for you, I guess that's ok. Please let us know if you need any further assistance.
Hello! I'm actually hitting the exact same bug. The environment variables are set in the configurations as you showed above, but they are not actually passed in when I run go build or test.
I am running
The following is the console output (sorry for the redacted parts):
This is the environment setup
@Antonio, can you please confirm that there's no whitespace before `WATCH_NAMESPACE` in the environment variable?
You can also run the following line before your check for the variable to see if the variable is sent: "fmt.Println(os.Environ)".
Thank you.
You are right! *facepalm*
@... Hello, How can I append an environment variable into system environment variable in goland? Example, My system environment variable has this: `TName=a`, and I want add `b` to variable `TName`, I write `TNAME=%TNAME%;b`, but it doesn't work!
Thank you very much.
Double Pointer Hello, at the moment this is not possible in GoLand. Feel free to go to our YouTrack and create a new feature request.
I'm new to using Goland and loving it so far but this is the first issue I've run into and not been able to solve myself.
I am having the same issue where I've set the test config environment variables but the tests aren't picking them up for some reason. Upon debugging, I found that Goland was adding an extra `;` to the command it invoked. E.g. `key=value; command` instead of `key=value command` which worked locally whereas the former (which Goland created) did not.
I tweaked my test to just print the `os.Environ()` and so from my logs you can see what was invoked and what the environ read in the tests was (sorry for the verbosity):
```
SONOBUOY_CLI=/Users/jschnake/go/src/github.com/vmware-tanzu/sonobuoy/sonobuoy GOTARGET=github.com/vmware-tanzu/sonobuoy KUBECONFIG=/Users/jschnake/.kube/config a=b; go test $GOTARGET/test/integration -update -v -tags integration -run 'TestPluginsPersistThroughLogQuery'
...
...
ENVIRON IS... [PATH=/usr/local/go/bin:/Users/jschnake/go/bin:/Users/jschnake/bin:/usr/local/bin:/Users/jschnake/go/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin TERM=xterm-256color COMMAND_MODE=unix2003 __INTELLIJ_COMMAND_HISTFILE__=/Users/jschnake/Library/Caches/JetBrains/GoLand2021.2/terminal/history/sonobuoy-history5 LOGNAME=jschnake XPC_SERVICE_NAME=0 __CFBundleIdentifier=com.jetbrains.goland SHELL=/bin/zsh GOPATH=/Users/jschnake/go USER=jschnake GOROOT=/usr/local/go TMPDIR=/var/folders/8j/c6w1d8tn3tsg3k9w7gc9mpk80000gp/T/ TERMINAL_EMULATOR=JetBrains-JediTerm LOGIN_SHELL=1 GO111MODULE=on SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.D94jdYCtQi/Listeners XPC_FLAGS=0x0 TERM_SESSION_ID=f0399228-4525-47be-9779-0f9a322cba53 __CF_USER_TEXT_ENCODING=0x1F6:0x0:0x0 LC_CTYPE=en_US.UTF-8 HOME=/Users/jschnake SHLVL=1 PWD=/Users/jschnake/go/src/github.com/vmware-tanzu/sonobuoy/test/integration OLDPWD=/Users/jschnake/go/src/github.com/vmware-tanzu/sonobuoy ZSH=/Users/jschnake/.oh-my-zsh PAGER=less LESS=-R LSCOLORS=Gxfxcxdxbxegedabagacad EDITOR=goland sono=/Users/jschnake/go/src/github.com/vmware-tanzu/sonobuoy _=/usr/local/go/bin/go]
```
None of those values I set were actually read in the code. For the record, I am running this as a Bash script instead of a `go test` since it lined up with other parts of my dev flow already.
Is this a bug or is there something I could have done to change how that was run?
GoLand 2021.2.2
Build #GO-212.5080.74, built on August 31, 2021
Licensed to GoLand Evaluator
Expiration date: October 15, 2021
Runtime version: 11.0.11+9-b1504.16 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 11.5
GC: G1 Young Generation, G1 Old Generation
Memory: 2048M
Cores: 16
Registry: suggest.all.run.configurations.from.context=true, ide.completion.variant.limit=500
Non-Bundled Plugins: com.planetexpress.go_struct_tag_generator (1.2.8)
Schnake John, I can't reproduce the issue with extra ; so far in my environment. So, I'd like to ask you some details:
It would be great if you could provide the exact steps to reproduce to understand your case better.
Thank you.