-
Notifications
You must be signed in to change notification settings - Fork 8
/
status_test.go
90 lines (71 loc) · 1.79 KB
/
status_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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package zebra_test
import (
"testing"
"github.com/project-safari/zebra"
"github.com/stretchr/testify/assert"
)
func TestDefaultStatus(t *testing.T) {
t.Parallel()
assert := assert.New(t)
s := zebra.DefaultStatus()
assert.NotNil(s)
assert.Equal(zebra.None, s.Fault)
assert.Equal(zebra.Free, s.LeaseStatus)
assert.Equal("", s.UsedBy)
assert.Equal(zebra.Inactive, s.State)
}
func TestValidateStatus(t *testing.T) {
t.Parallel()
assert := assert.New(t)
s := zebra.Status{
Fault: 8,
LeaseStatus: 8,
UsedBy: "",
State: 8,
}
assert.NotNil(s.Validate())
s.Fault = zebra.Critical
assert.NotNil(s.Validate())
s.LeaseStatus = zebra.Free
assert.NotNil(s.Validate())
s.State = zebra.Inactive
assert.Nil(s.Validate())
}
func TestString(t *testing.T) {
t.Parallel()
assert := assert.New(t)
var f zebra.Fault = 8
var l zebra.LeaseStatus = 8
var s zebra.State = 8
assert.Equal("unknown", f.String())
assert.Equal("unknown", l.String())
assert.Equal("unknown", s.String())
}
func TestUnmarshal(t *testing.T) {
t.Parallel()
assert := assert.New(t)
f := zebra.None
assert.Equal("none", f.String())
b, err := f.MarshalText()
assert.Nil(err)
assert.NotEmpty(b)
assert.Nil(f.UnmarshalText(b))
assert.Equal(zebra.None, f)
l := zebra.Free
assert.Equal("free", l.String())
b, err = l.MarshalText()
assert.Nil(err)
assert.NotEmpty(b)
assert.Nil(l.UnmarshalText(b))
assert.Equal(zebra.Free, l)
s := zebra.Active
assert.Equal("active", s.String())
b, err = s.MarshalText()
assert.Nil(err)
assert.NotEmpty(b)
assert.Nil(s.UnmarshalText(b))
assert.Equal(zebra.Active, s)
assert.Equal(zebra.ErrLeaseStatus, l.UnmarshalText([]byte("zzz")))
assert.Equal(zebra.ErrFault, f.UnmarshalText([]byte("zzz")))
assert.Equal(zebra.ErrState, s.UnmarshalText([]byte("zzz")))
}