| 1 |
# Test passing environment variables to scripts with the go command on PATH |
| 2 |
# |
| 3 |
# Below where we check the output of testscript -v, we have to match against |
| 4 |
# the string literal $WORK because testscript rewrites the actual directory |
| 5 |
# to $WORK. Hence we don't want to expand this script's $WORK in such a comparison. |
| 6 |
# |
| 7 |
# This is the counterpart to env_var_no_go.txt |
| 8 |
|
| 9 |
unquote noproxy.txt |
| 10 |
unquote withproxy.txt |
| 11 |
|
| 12 |
# Baseline |
| 13 |
testscript -v noproxy.txt |
| 14 |
stdout ^BANANA=$ |
| 15 |
stdout '^GOPATH=\$WORK[/\\]\.gopath'$ |
| 16 |
stdout ^GOPROXY=https://proxy.golang.org,direct$ |
| 17 |
! stderr .+ |
| 18 |
|
| 19 |
env BANANA=banana |
| 20 |
env GOPATH=$WORK/ourgopath |
| 21 |
|
| 22 |
env GOPROXY= |
| 23 |
|
| 24 |
# no GOPROXY, no pass-through, no proxy |
| 25 |
testscript -v noproxy.txt |
| 26 |
stdout ^BANANA=$ |
| 27 |
stdout '^GOPATH=\$WORK[/\\]\.gopath'$ |
| 28 |
stdout ^GOPROXY=https://proxy.golang.org,direct$ |
| 29 |
! stderr .+ |
| 30 |
|
| 31 |
# no GOPROXY, no pass-through, with proxy |
| 32 |
testscript -v withproxy.txt |
| 33 |
stdout ^BANANA=$ |
| 34 |
stdout '^GOPATH=\$WORK[/\\]\.gopath'$ |
| 35 |
stdout ^GOPROXY=http://.*/mod$ |
| 36 |
! stderr .+ |
| 37 |
|
| 38 |
# no GOPROXY, with pass-through, no proxy |
| 39 |
testscript -v -e BANANA -e GOPATH -e GOPROXY noproxy.txt |
| 40 |
stdout ^BANANA=banana$ |
| 41 |
stdout ^GOPATH=${WORK@R}[/\\]ourgopath$ |
| 42 |
stdout ^GOPROXY=$ |
| 43 |
! stderr .+ |
| 44 |
|
| 45 |
# no GOPROXY, with pass-through, with proxy |
| 46 |
testscript -v -e BANANA -e GOPATH -e GOPROXY withproxy.txt |
| 47 |
stdout ^BANANA=banana$ |
| 48 |
stdout ^GOPATH=${WORK@R}[/\\]ourgopath$ |
| 49 |
stdout ^GOPROXY=$ |
| 50 |
! stderr .+ |
| 51 |
|
| 52 |
setfilegoproxy $WORK/proxy |
| 53 |
|
| 54 |
# with GOPROXY, no pass-through, no proxy |
| 55 |
testscript -v noproxy.txt |
| 56 |
stdout ^BANANA=$ |
| 57 |
stdout '^GOPATH=\$WORK[/\\]\.gopath'$ |
| 58 |
stdout ^GOPROXY=$GOPROXY$ |
| 59 |
! stderr .+ |
| 60 |
|
| 61 |
# with GOPROXY, no pass-through, with proxy |
| 62 |
testscript -v withproxy.txt |
| 63 |
stdout ^BANANA=$ |
| 64 |
stdout '^GOPATH=\$WORK[/\\]\.gopath'$ |
| 65 |
stdout ^GOPROXY=http://.*/mod$ |
| 66 |
! stderr .+ |
| 67 |
|
| 68 |
# with GOPROXY, with pass-through, no proxy |
| 69 |
testscript -v -e BANANA -e GOPATH -e GOPROXY noproxy.txt |
| 70 |
stdout ^BANANA=banana$ |
| 71 |
stdout ^GOPATH=${WORK@R}[/\\]ourgopath$ |
| 72 |
stdout ^GOPROXY=$GOPROXY$ |
| 73 |
! stderr .+ |
| 74 |
|
| 75 |
# with GOPROXY, with pass-through, with proxy |
| 76 |
testscript -v -e BANANA -e GOPATH -e GOPROXY withproxy.txt |
| 77 |
stdout ^BANANA=banana$ |
| 78 |
stdout ^GOPATH=${WORK@R}[/\\]ourgopath$ |
| 79 |
stdout ^GOPROXY=$GOPROXY$ |
| 80 |
! stderr .+ |
| 81 |
|
| 82 |
-- noproxy.txt -- |
| 83 |
>env BANANA |
| 84 |
>env GOPATH |
| 85 |
>env GOPROXY |
| 86 |
|
| 87 |
-- withproxy.txt -- |
| 88 |
>env BANANA |
| 89 |
>env GOPATH |
| 90 |
>env GOPROXY |
| 91 |
|
| 92 |
>-- .gomodproxy/fruit.com_v1.0.0/.mod -- |
| 93 |
>module fruit.com |
| 94 |
> |
| 95 |
>-- .gomodproxy/fruit.com_v1.0.0/.info -- |
| 96 |
>{"Version":"v1.0.0","Time":"2018-10-22T18:45:39Z"} |
| 97 |
> |
| 98 |
>-- .gomodproxy/fruit.com_v1.0.0/go.mod -- |
| 99 |
>module fruit.com |
| 100 |
> |
| 101 |
>-- .gomodproxy/fruit.com_v1.0.0/fruit/fruit.go -- |
| 102 |
>package fruit |
| 103 |
> |
| 104 |
>const Apple = "apple" |
| 105 |
>-- .gomodproxy/fruit.com_v1.0.0/coretest/coretest.go -- |
| 106 |
>// package coretest becomes a candidate for the missing |
| 107 |
>// core import in main above |
| 108 |
>package coretest |
| 109 |
> |
| 110 |
>const Mandarin = "mandarin" |