-
Notifications
You must be signed in to change notification settings - Fork 0
/
manifold_test.go
76 lines (62 loc) · 1.9 KB
/
manifold_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
// Copyright 2017 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package dblogpruner_test
import (
"time"
"github.com/juju/errors"
"github.com/juju/testing"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"gopkg.in/juju/worker.v1"
"gopkg.in/juju/worker.v1/workertest"
"github.com/juju/juju/worker/dblogpruner"
)
type ManifoldSuite struct {
testing.IsolationSuite
stub testing.Stub
config dblogpruner.ManifoldConfig
worker worker.Worker
}
var _ = gc.Suite(&ManifoldSuite{})
func (s *ManifoldSuite) SetUpTest(c *gc.C) {
s.IsolationSuite.SetUpTest(c)
s.stub.ResetCalls()
s.config = s.validConfig()
s.worker = worker.NewRunner(worker.RunnerParams{})
s.AddCleanup(func(c *gc.C) { workertest.DirtyKill(c, s.worker) })
}
func (s *ManifoldSuite) validConfig() dblogpruner.ManifoldConfig {
return dblogpruner.ManifoldConfig{
ClockName: "clock",
StateName: "state",
PruneInterval: time.Hour,
NewWorker: func(config dblogpruner.Config) (worker.Worker, error) {
s.stub.AddCall("NewWorker", config)
return s.worker, s.stub.NextErr()
},
}
}
func (s *ManifoldSuite) TestValid(c *gc.C) {
c.Check(s.config.Validate(), jc.ErrorIsNil)
}
func (s *ManifoldSuite) TestMissingClockName(c *gc.C) {
s.config.ClockName = ""
s.checkNotValid(c, "empty ClockName not valid")
}
func (s *ManifoldSuite) TestMissingStateName(c *gc.C) {
s.config.StateName = ""
s.checkNotValid(c, "empty StateName not valid")
}
func (s *ManifoldSuite) TestZeroPruneInterval(c *gc.C) {
s.config.PruneInterval = 0
s.checkNotValid(c, "non-positive PruneInterval not valid")
}
func (s *ManifoldSuite) TestMissingNewWorker(c *gc.C) {
s.config.NewWorker = nil
s.checkNotValid(c, "nil NewWorker not valid")
}
func (s *ManifoldSuite) checkNotValid(c *gc.C, expect string) {
err := s.config.Validate()
c.Check(err, gc.ErrorMatches, expect)
c.Check(err, jc.Satisfies, errors.IsNotValid)
}