66 "testing"
77)
88
9- // Key is a declared environment variable name.
109type Key string
1110
1211const (
@@ -16,12 +15,10 @@ const (
1615 CI Key = "CI"
1716)
1817
19- // Get returns the value of the given environment variable.
2018func Get (key Key ) string {
2119 return os .Getenv (string (key ))
2220}
2321
24- // Require returns the value of the given environment variable, failing the test if it is not set.
2522func Require (t testing.TB , key Key ) string {
2623 t .Helper ()
2724 v := os .Getenv (string (key ))
@@ -31,20 +28,16 @@ func Require(t testing.TB, key Key) string {
3128 return v
3229}
3330
34- // Environ is a slice of "KEY=value" environment variable strings.
3531type Environ []string
3632
37- // Without returns the current process environment excluding the given keys.
3833func Without (keys ... Key ) Environ {
3934 return Environ (os .Environ ()).Without (keys ... )
4035}
4136
42- // With returns the current process environment with key=value appended.
4337func With (key Key , value string ) Environ {
4438 return Environ (os .Environ ()).With (key , value )
4539}
4640
47- // Without returns a copy of e excluding any variable whose key matches one of the given keys.
4841func (e Environ ) Without (keys ... Key ) Environ {
4942 var result Environ
5043 for _ , entry := range e {
@@ -62,7 +55,6 @@ func (e Environ) Without(keys ...Key) Environ {
6255 return result
6356}
6457
65- // With returns a copy of e with key=value appended.
6658func (e Environ ) With (key Key , value string ) Environ {
6759 return append (e , string (key )+ "=" + value )
6860}
0 commit comments