forked from juju/juju
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlife_test.go
93 lines (78 loc) · 2.11 KB
/
life_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
91
92
93
// Copyright 2016 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package life_test
import (
"github.com/juju/errors"
"github.com/juju/testing"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"github.com/juju/juju/core/life"
)
type LifeSuite struct {
testing.IsolationSuite
}
var _ = gc.Suite(&LifeSuite{})
func (*LifeSuite) TestValidateValid(c *gc.C) {
for i, test := range []life.Value{
life.Alive, life.Dying, life.Dead,
} {
c.Logf("test %d: %s", i, test)
err := test.Validate()
c.Check(err, jc.ErrorIsNil)
}
}
func (*LifeSuite) TestValidateInvalid(c *gc.C) {
for i, test := range []life.Value{
"", "bad", "resurrected",
" alive", "alive ", "Alive",
} {
c.Logf("test %d: %s", i, test)
err := test.Validate()
c.Check(err, jc.ErrorIs, errors.NotValid)
c.Check(err, gc.ErrorMatches, `life value ".*" not valid`)
}
}
func (*LifeSuite) TestIsAliveSuccess(c *gc.C) {
c.Check(life.IsAlive(life.Alive), jc.IsTrue)
}
func (*LifeSuite) TestIsAliveFailure(c *gc.C) {
for i, test := range []life.Value{
life.Dying, life.Dead, "", "bad", "ALIVE",
} {
c.Logf("test %d: %s", i, test)
c.Check(life.IsAlive(test), jc.IsFalse)
}
}
func (*LifeSuite) TestIsNotAliveFailure(c *gc.C) {
c.Check(life.IsNotAlive(life.Alive), jc.IsFalse)
}
func (*LifeSuite) TestIsNotAliveSuccess(c *gc.C) {
for i, test := range []life.Value{
life.Dying, life.Dead, "", "bad", "ALIVE",
} {
c.Logf("test %d: %s", i, test)
c.Check(life.IsNotAlive(test), jc.IsTrue)
}
}
func (*LifeSuite) TestIsNotDeadFailure(c *gc.C) {
c.Check(life.IsNotDead(life.Dead), jc.IsFalse)
}
func (*LifeSuite) TestIsNotDeadSuccess(c *gc.C) {
for i, test := range []life.Value{
life.Alive, life.Dying, "", "bad", "DEAD",
} {
c.Logf("test %d: %s", i, test)
c.Check(life.IsNotDead(test), jc.IsTrue)
}
}
func (*LifeSuite) TestIsDeadSuccess(c *gc.C) {
c.Check(life.IsDead(life.Dead), jc.IsTrue)
}
func (*LifeSuite) TestIsDeadFailure(c *gc.C) {
for i, test := range []life.Value{
life.Alive, life.Dying, "", "bad", "DEAD",
} {
c.Logf("test %d: %s", i, test)
c.Check(life.IsDead(test), jc.IsFalse)
}
}