~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/worker/charmrevision/validate_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2013 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package charmrevision_test
 
5
 
 
6
import (
 
7
        "time"
 
8
 
 
9
        "github.com/juju/errors"
 
10
        "github.com/juju/testing"
 
11
        jc "github.com/juju/testing/checkers"
 
12
        "github.com/juju/utils/clock"
 
13
        gc "gopkg.in/check.v1"
 
14
 
 
15
        "github.com/juju/juju/worker/charmrevision"
 
16
)
 
17
 
 
18
type ValidateSuite struct {
 
19
        testing.IsolationSuite
 
20
        config charmrevision.Config
 
21
}
 
22
 
 
23
var _ = gc.Suite(&ValidateSuite{})
 
24
 
 
25
func (s *ValidateSuite) SetUpTest(c *gc.C) {
 
26
        s.IsolationSuite.SetUpTest(c)
 
27
        s.config = charmrevision.Config{
 
28
                RevisionUpdater: struct{ charmrevision.RevisionUpdater }{},
 
29
                Clock:           struct{ clock.Clock }{},
 
30
                Period:          time.Hour,
 
31
        }
 
32
}
 
33
 
 
34
func (s *ValidateSuite) TestValid(c *gc.C) {
 
35
        err := s.config.Validate()
 
36
        c.Check(err, jc.ErrorIsNil)
 
37
}
 
38
 
 
39
func (s *ValidateSuite) TestNilRevisionUpdater(c *gc.C) {
 
40
        s.config.RevisionUpdater = nil
 
41
        s.checkNotValid(c, "nil RevisionUpdater not valid")
 
42
}
 
43
 
 
44
func (s *ValidateSuite) TestNilClock(c *gc.C) {
 
45
        s.config.Clock = nil
 
46
        s.checkNotValid(c, "nil Clock not valid")
 
47
}
 
48
 
 
49
func (s *ValidateSuite) TestBadPeriods(c *gc.C) {
 
50
        for i, period := range []time.Duration{
 
51
                0, -time.Nanosecond, -time.Hour,
 
52
        } {
 
53
                c.Logf("test %d", i)
 
54
                s.config.Period = period
 
55
                s.checkNotValid(c, "non-positive Period not valid")
 
56
        }
 
57
}
 
58
 
 
59
func (s *ValidateSuite) checkNotValid(c *gc.C, match string) {
 
60
        check := func(err error) {
 
61
                c.Check(err, jc.Satisfies, errors.IsNotValid)
 
62
                c.Check(err, gc.ErrorMatches, match)
 
63
        }
 
64
        err := s.config.Validate()
 
65
        check(err)
 
66
 
 
67
        worker, err := charmrevision.NewWorker(s.config)
 
68
        c.Check(worker, gc.IsNil)
 
69
        check(err)
 
70
}