-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathenv_test.go
More file actions
48 lines (41 loc) · 1.14 KB
/
env_test.go
File metadata and controls
48 lines (41 loc) · 1.14 KB
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
package command_test
import (
"testing"
"lesiw.io/command"
"lesiw.io/command/mem"
)
func TestEnvQueryMachine(t *testing.T) {
m := mem.Machine()
ctx := command.WithEnv(t.Context(), map[string]string{
"TEST_VAR": "from_machine",
})
got := command.Env(ctx, m, "TEST_VAR")
if want := "from_machine"; got != want {
t.Errorf("Env(TEST_VAR) = %q, want %q", got, want)
}
got = command.Env(ctx, m, "NONEXISTENT")
if want := ""; got != want {
t.Errorf("Env(NONEXISTENT) = %q, want %q", got, want)
}
}
func TestEnvContextOverridesMachine(t *testing.T) {
m := mem.Machine()
ctx := command.WithEnv(t.Context(), map[string]string{
"HOME": "/home/mem",
})
if got, want := command.Env(ctx, m, "HOME"), "/home/mem"; got != want {
t.Errorf("Env(HOME) = %q, want %q", got, want)
}
}
func TestWithoutEnv(t *testing.T) {
ctx := command.WithEnv(t.Context(), map[string]string{
"FOO": "bar",
"BAZ": "qux",
})
if got, want := len(command.Envs(ctx)), 2; got != want {
t.Fatalf("command.Envs() got %d vars, want %d", got, want)
}
if got := command.Envs(command.WithoutEnv(ctx)); got != nil {
t.Errorf("command.Envs() = %v, want nil", got)
}
}