-
Notifications
You must be signed in to change notification settings - Fork 0
/
vars_test.go
74 lines (59 loc) · 1.21 KB
/
vars_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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package env
import (
"errors"
"os"
"testing"
"github.com/blugnu/test"
)
func TestVars_Names(t *testing.T) {
// ACT
result := Vars{
"VAR3": "value2",
"VAR1": "value1",
"VAR2": "value2",
}.Names()
// ASSERT
test.That(t, result).Equals([]string{"VAR1", "VAR2", "VAR3"})
}
func TestVars_Set(t *testing.T) {
// ARRANGE
defer State().Reset()
os.Clearenv()
// ACT
err := Vars{
"VAR1": "value1",
"VAR2": "value2",
}.Set()
// ASSERT
test.That(t, err).IsNil()
test.That(t, os.Getenv("VAR1")).Equals("value1")
test.That(t, os.Getenv("VAR2")).Equals("value2")
}
func TestVars_Set_WhenSetenvFails(t *testing.T) {
// ARRANGE
defer State().Reset()
seterr := errors.New("setenv error")
defer test.Using(&osSetenv, func(string, string) error {
return seterr
})()
// ACT
err := Vars{"VAR1": "value1"}.Set()
// ASSERT
test.Error(t, err).Is(seterr)
}
func TestVars_String(t *testing.T) {
// ACT
result := Vars{
"VAR3": "value3",
"VAR1": "value1",
"VAR2": "value2",
}.String()
// ASSERT
test.That(t, result).Equals(`[VAR1="value1",VAR2="value2",VAR3="value3"]`)
}
func TestVars_String_WhenEmpty(t *testing.T) {
// ACT
result := Vars{}.String()
// ASSERT
test.That(t, result).Equals("[]")
}