github.com/drone/runner-go@v1.12.0/environ/expand_test.go (about) 1 // Copyright 2019 Drone.IO Inc. All rights reserved. 2 // Use of this source code is governed by the Polyform License 3 // that can be found in the LICENSE file. 4 5 package environ 6 7 import ( 8 "os" 9 "testing" 10 ) 11 12 func TestExpand(t *testing.T) { 13 defer func() { 14 getenv = os.Getenv 15 }() 16 17 getenv = func(string) string { 18 return "/bin:/usr/local/bin" 19 } 20 21 before := map[string]string{ 22 "USER": "root", 23 "HOME": "/home/$USER", // does not expect 24 "PATH": "/go/bin:$PATH", 25 } 26 27 after := Expand(before) 28 if got, want := after["PATH"], "/go/bin:/bin:/usr/local/bin"; got != want { 29 t.Errorf("Got PATH %q, want %q", got, want) 30 } 31 if got, want := after["USER"], "root"; got != want { 32 t.Errorf("Got USER %q, want %q", got, want) 33 } 34 // only the PATH variable should expand. No other variables 35 // should be expanded. 36 if got, want := after["HOME"], "/home/$USER"; got != want { 37 t.Errorf("Got HOME %q, want %q", got, want) 38 } 39 }