Debian Codegraph @

testing/condition/condition_test.go

raw
1 /*
2 Copyright 2013-2014 Canonical Ltd.
3
4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU General Public License version 3, as published
6 by the Free Software Foundation.
7
8 This program is distributed in the hope that it will be useful, but
9 WITHOUT ANY WARRANTY; without even the implied warranties of
10 MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 PURPOSE. See the GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License along
14 with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 package condition
18
19 import (
20 "testing"
21
22 gocheck "gopkg.in/check.v1" // not into . because we have our own Not
23 )
24
25 // hook up gocheck
26 func Test(t *testing.T) { gocheck.TestingT(t) }
27
28 type CondSuite struct{}
29
30 var _ = gocheck.Suite(&CondSuite{})
31
32 func (s *CondSuite) TestConditionWorkTrue(c *gocheck.C) {
33 cond := Work(true)
34 c.Check(cond.OK(), gocheck.Equals, true)
35 c.Check(cond.String(), gocheck.Equals, "Always Working.")
36 }
37
38 func (s *CondSuite) TestConditionWorkFalse(c *gocheck.C) {
39 cond := Work(false)
40 c.Check(cond.OK(), gocheck.Equals, false)
41 c.Check(cond.String(), gocheck.Equals, "Never Working.")
42 }
43
44 func (s *CondSuite) TestConditionFail2Work(c *gocheck.C) {
45 cond := Fail2Work(2)
46 c.Check(cond.String(), gocheck.Equals, "Still Broken, 2 to go.")
47 c.Check(cond.OK(), gocheck.Equals, false)
48 c.Check(cond.String(), gocheck.Equals, "Still Broken, 1 to go.")
49 c.Check(cond.OK(), gocheck.Equals, false)
50 c.Check(cond.String(), gocheck.Equals, "Working.")
51 c.Check(cond.OK(), gocheck.Equals, true)
52 c.Check(cond.String(), gocheck.Equals, "Working.")
53 c.Check(cond.OK(), gocheck.Equals, true)
54 c.Check(cond.String(), gocheck.Equals, "Working.")
55 }
56
57 func (s *CondSuite) TestConditionNot(c *gocheck.C) {
58 cond := Not(Fail2Work(1))
59 c.Check(cond.String(), gocheck.Equals, "Not Still Broken, 1 to go.")
60 c.Check(cond.OK(), gocheck.Equals, true)
61 c.Check(cond.String(), gocheck.Equals, "Not Working.")
62 c.Check(cond.OK(), gocheck.Equals, false)
63 }
64
65 func (s *CondSuite) TestConditionChain(c *gocheck.C) {
66 cond := Chain(2, Work(true), 3, Work(false), 0, Work(true))
67 c.Check(cond.String(), gocheck.Equals, "2 of Always Working. Then: 3 of Never Working. Then: 0 of Always Working.")
68 c.Check(cond.OK(), gocheck.Equals, true)
69 c.Check(cond.OK(), gocheck.Equals, true)
70 c.Check(cond.OK(), gocheck.Equals, false)
71 c.Check(cond.OK(), gocheck.Equals, false)
72 c.Check(cond.OK(), gocheck.Equals, false)
73 c.Check(cond.OK(), gocheck.Equals, true)
74 // c.Check(cond.OK(), gocheck.Equals, true)
75 // c.Check(cond.OK(), gocheck.Equals, true)
76 // c.Check(cond.OK(), gocheck.Equals, true)
77 }