-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
env_test.go
47 lines (38 loc) · 1009 Bytes
/
env_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (c) 2020, Roel Schut. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package env
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestSetenv(t *testing.T) {
t.Run("err", func(t *testing.T) {
wantErr := os.Setenv("", "foobar")
haveErr := Setenv("", "foobar")
assert.EqualError(t, haveErr, wantErr.Error())
})
}
func TestEnviron(t *testing.T) {
source := os.Environ()
target := Environ()
wantLen := len(source)
for _, e := range source {
if e[0] == '=' {
// exclude env variables like =::=:: or =R:=R:\\
wantLen--
}
}
assert.Exactly(t, wantLen, len(target))
for k, v := range target {
have := k + "=" + v.String()
assert.Contains(t, source, have, "raw env string `%s` not in os.Environ()", have)
}
}
func TestSystem_Lookup(t *testing.T) {
t.Run("not found", func(t *testing.T) {
_, err := System().Lookup(randKey())
assert.True(t, IsNotFound(err))
})
}