Skip to content

Commit da82540

Browse files
authored
Add tests for env var application order (#645)
## Summary Also tests the `PWD` special logic ## How was it tested? ``` go test ./testscripts/testscripts_test.go ```
1 parent 1a9d0e8 commit da82540

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

testscripts/run/env.test.txt

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,29 @@ env DEVBOX_FOO=baz
3535
exec devbox run echo '$CONFIG_VAR2'
3636
stdout 'baz'
3737

38-
# TODO: test order/overwriting of variables
38+
# Vars in devbox that refer to $PWD should get the project dir
39+
env PWD=/test-pwd
40+
exec devbox run echo '$CONFIG_VAR3'
41+
! stdout '/test-pwd'
42+
43+
# Variables are applied in order: nix vars, DEVBOX_*, leaked, leakedForShell, fixed/hard-coded vars,
44+
# plugin vars, and config vars. It really only makes sense to test for plugin and config vars order.
45+
# Note that the nginx plugin defines NGINX_CONFDIR, NGINX_PATH_PREFIX, and NGINX_TMPDIR.
46+
env NGINX_TMPDIR="to-be-overwritten-by-plugin"
47+
exec devbox run echo '$NGINX_TMPDIR'
48+
! stdout 'to-be-overwritten-by-plugin'
49+
stdout '.devbox/virtenv/nginx/temp'
50+
51+
exec devbox run echo '$NGINX_CONFDIR'
52+
stdout 'devbox-json-override'
3953

4054
-- devbox.json --
4155
{
42-
"packages": [],
56+
"packages": ["nginx"],
4357
"env": {
4458
"CONFIG_VAR1": "abc",
45-
"CONFIG_VAR2": "$DEVBOX_FOO"
59+
"CONFIG_VAR2": "$DEVBOX_FOO",
60+
"CONFIG_VAR3": "${PWD}",
61+
"NGINX_CONFDIR": "devbox-json-override"
4662
}
4763
}

0 commit comments

Comments
 (0)