-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathenv_test.go
More file actions
75 lines (58 loc) · 1.57 KB
/
env_test.go
File metadata and controls
75 lines (58 loc) · 1.57 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
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
75
package iron
import (
"bytes"
"encoding/json"
"os"
"testing"
)
func TestEnvLoadFromFile(t *testing.T) {
f, err := os.CreateTemp(t.TempDir(), "")
if err != nil {
t.Fatal(err)
}
defer os.Remove(f.Name())
if err = os.WriteFile(f.Name(), []byte(`{"irods_zone_name": "testZone"}`), 0o644); err != nil {
t.Fatal(err)
}
env := Env{}
if err = env.LoadFromFile(f.Name()); err != nil {
t.Fatal(err)
}
if env.Zone != "testZone" {
t.Fatalf("expected testZone, got %s", env.Zone)
}
}
func TestEnvMarshal(t *testing.T) {
var (
zero int
one = 1
)
envs := []Env{
{Zone: "testZone"},
{Zone: "testZone", IrodsAuthenticationUID: &zero},
{Zone: "testZone", IrodsAuthenticationUID: &one},
}
for i, env := range envs {
payload, err := json.Marshal(env)
if err != nil {
t.Fatal(err)
}
expected := i > 0
if !expected && bytes.Contains(payload, []byte("irods_authentication_uid")) {
t.Errorf("[%d] expected payload to not contain irods_authentication_uid, got %s", i, payload)
}
if expected && !bytes.Contains(payload, []byte("irods_authentication_uid")) {
t.Errorf("[%d] expected payload to contain irods_authentication_uid, got %s", i, payload)
}
var unmarshaled Env
if err = json.Unmarshal(payload, &unmarshaled); err != nil {
t.Fatal(err)
}
if expected && unmarshaled.IrodsAuthenticationUID == nil {
t.Errorf("[%d] expected unmarshaled.IrodsAuthenticationUID to not be nil", i)
}
if !expected && unmarshaled.IrodsAuthenticationUID != nil {
t.Errorf("[%d] expected unmarshaled.IrodsAuthenticationUID to be nil", i)
}
}
}