github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/core/life/life_test.go (about)

     1  // Copyright 2016 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package life_test
     5  
     6  import (
     7  	"github.com/juju/errors"
     8  	"github.com/juju/testing"
     9  	jc "github.com/juju/testing/checkers"
    10  	gc "gopkg.in/check.v1"
    11  
    12  	"github.com/juju/juju/core/life"
    13  )
    14  
    15  type LifeSuite struct {
    16  	testing.IsolationSuite
    17  }
    18  
    19  var _ = gc.Suite(&LifeSuite{})
    20  
    21  func (*LifeSuite) TestValidateValid(c *gc.C) {
    22  	for i, test := range []life.Value{
    23  		life.Alive, life.Dying, life.Dead,
    24  	} {
    25  		c.Logf("test %d: %s", i, test)
    26  		err := test.Validate()
    27  		c.Check(err, jc.ErrorIsNil)
    28  	}
    29  }
    30  
    31  func (*LifeSuite) TestValidateInvalid(c *gc.C) {
    32  	for i, test := range []life.Value{
    33  		"", "bad", "resurrected",
    34  		" alive", "alive ", "Alive",
    35  	} {
    36  		c.Logf("test %d: %s", i, test)
    37  		err := life.Value(test).Validate()
    38  		c.Check(err, jc.Satisfies, errors.IsNotValid)
    39  		c.Check(err, gc.ErrorMatches, `life value ".*" not valid`)
    40  	}
    41  }
    42  
    43  func (*LifeSuite) TestIsNotAliveFailure(c *gc.C) {
    44  	c.Check(life.IsNotAlive(life.Alive), jc.IsFalse)
    45  }
    46  
    47  func (*LifeSuite) TestIsNotAliveSuccess(c *gc.C) {
    48  	for i, test := range []life.Value{
    49  		life.Dying, life.Dead, "", "bad", "ALIVE",
    50  	} {
    51  		c.Logf("test %d: %s", i, test)
    52  		c.Check(life.IsNotAlive(test), jc.IsTrue)
    53  	}
    54  }
    55  
    56  func (*LifeSuite) TestIsNotDeadFailure(c *gc.C) {
    57  	c.Check(life.IsNotDead(life.Dead), jc.IsFalse)
    58  }
    59  
    60  func (*LifeSuite) TestIsNotDeadSuccess(c *gc.C) {
    61  	for i, test := range []life.Value{
    62  		life.Alive, life.Dying, "", "bad", "DEAD",
    63  	} {
    64  		c.Logf("test %d: %s", i, test)
    65  		c.Check(life.IsNotDead(test), jc.IsTrue)
    66  	}
    67  }