forked from direnv/direnv
-
Notifications
You must be signed in to change notification settings - Fork 2
/
env_diff_test.go
56 lines (46 loc) · 1.01 KB
/
env_diff_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
package main
import (
"reflect"
"testing"
)
func TestEnvDiff(t *testing.T) {
diff := &EnvDiff{map[string]string{"FOO": "bar"}, map[string]string{"BAR": "baz"}}
out := diff.Serialize()
diff2, err := LoadEnvDiff(out)
if err != nil {
t.Error("parse error", err)
}
if len(diff2.Prev) != 1 {
t.Error("len(diff2.prev) != 1", len(diff2.Prev))
}
if len(diff2.Next) != 1 {
t.Error("len(diff2.next) != 0", len(diff2.Next))
}
}
// Issue #114
// Check that empty environment variables correctly appear in the diff
func TestEnvDiffEmptyValue(t *testing.T) {
before := Env{}
after := Env{"FOO": ""}
diff := BuildEnvDiff(before, after)
if !reflect.DeepEqual(diff.Next, map[string]string(after)) {
t.Errorf("diff.Next != after (%#+v != %#+v)", diff.Next, after)
}
}
func TestIgnoredEnv(t *testing.T) {
if !IgnoredEnv(DIRENV_BASH) {
t.Fail()
}
if IgnoredEnv(DIRENV_DIFF) {
t.Fail()
}
if !IgnoredEnv("_") {
t.Fail()
}
if !IgnoredEnv("__fish_foo") {
t.Fail()
}
if !IgnoredEnv("__fishx") {
t.Fail()
}
}