-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
69 lines (63 loc) · 1.46 KB
/
main_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
package main
import (
"os"
"path/filepath"
"slices"
"testing"
)
func TestEnvv(t *testing.T) {
tests := []struct {
environ []string
files map[string]string
want []string
}{
{
environ: []string{"foo=bar"},
files: map[string]string{},
want: []string{"foo=bar"},
},
{
environ: []string{"foo=bar"},
files: map[string]string{"baz": "baz"},
want: []string{"foo=bar", "baz=baz"},
},
{
environ: []string{"foo=bar"},
files: map[string]string{"baz": "baz\t\n"},
want: []string{"foo=bar", "baz=baz"},
},
{
environ: []string{"foo=bar"},
files: map[string]string{"baz": "baz "},
want: []string{"foo=bar", "baz=baz"},
},
{
environ: []string{"foo=bar"},
files: map[string]string{"baz": "baz\nbaz"},
want: []string{"foo=bar", "baz=baz\nbaz"},
},
{
environ: []string{"foo=bar"},
files: map[string]string{"foo": ""},
want: []string{},
},
}
for _, test := range tests {
t.Run("", func(t *testing.T) {
dir, err := os.MkdirTemp("", "envv")
if err != nil {
t.Fatalf("unexpected err creating tempdir: %v", err)
}
for name, contents := range test.files {
os.WriteFile(filepath.Join(dir, name), []byte(contents), os.ModePerm)
}
got, err := envv(test.environ, dir)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
if !slices.Equal(test.want, got) {
t.Fatalf("envv slices did not match want=%v got=%v", test.want, got)
}
})
}
}