~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/worker/migrationmaster/manifoldconfig_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 2016 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package migrationmaster_test
 
5
 
 
6
import (
 
7
        "github.com/juju/errors"
 
8
        "github.com/juju/testing"
 
9
        jc "github.com/juju/testing/checkers"
 
10
        "github.com/juju/utils/clock"
 
11
        gc "gopkg.in/check.v1"
 
12
 
 
13
        "github.com/juju/juju/api/base"
 
14
        "github.com/juju/juju/worker"
 
15
        "github.com/juju/juju/worker/migrationmaster"
 
16
)
 
17
 
 
18
type ManifoldConfigSuite struct {
 
19
        testing.IsolationSuite
 
20
        config migrationmaster.ManifoldConfig
 
21
}
 
22
 
 
23
var _ = gc.Suite(&ManifoldConfigSuite{})
 
24
 
 
25
func (s *ManifoldConfigSuite) SetUpTest(c *gc.C) {
 
26
        s.IsolationSuite.SetUpTest(c)
 
27
        s.config = s.validConfig()
 
28
}
 
29
 
 
30
func (s *ManifoldConfigSuite) validConfig() migrationmaster.ManifoldConfig {
 
31
        return migrationmaster.ManifoldConfig{
 
32
                AgentName:     "agent",
 
33
                APICallerName: "api-caller",
 
34
                FortressName:  "fortress",
 
35
                Clock:         struct{ clock.Clock }{},
 
36
                NewFacade:     func(base.APICaller) (migrationmaster.Facade, error) { return nil, nil },
 
37
                NewWorker:     func(migrationmaster.Config) (worker.Worker, error) { return nil, nil },
 
38
        }
 
39
}
 
40
 
 
41
func (s *ManifoldConfigSuite) TestValid(c *gc.C) {
 
42
        c.Check(s.config.Validate(), jc.ErrorIsNil)
 
43
}
 
44
 
 
45
func (s *ManifoldConfigSuite) TestMissingAgentName(c *gc.C) {
 
46
        s.config.AgentName = ""
 
47
        s.checkNotValid(c, "empty AgentName not valid")
 
48
}
 
49
 
 
50
func (s *ManifoldConfigSuite) TestMissingAPICallerName(c *gc.C) {
 
51
        s.config.APICallerName = ""
 
52
        s.checkNotValid(c, "empty APICallerName not valid")
 
53
}
 
54
 
 
55
func (s *ManifoldConfigSuite) TestMissingFortressName(c *gc.C) {
 
56
        s.config.FortressName = ""
 
57
        s.checkNotValid(c, "empty FortressName not valid")
 
58
}
 
59
 
 
60
func (s *ManifoldConfigSuite) TestMissingClock(c *gc.C) {
 
61
        s.config.Clock = nil
 
62
        s.checkNotValid(c, "nil Clock not valid")
 
63
}
 
64
 
 
65
func (s *ManifoldConfigSuite) TestMissingNewFacade(c *gc.C) {
 
66
        s.config.NewFacade = nil
 
67
        s.checkNotValid(c, "nil NewFacade not valid")
 
68
}
 
69
 
 
70
func (s *ManifoldConfigSuite) TestMissingNewWorker(c *gc.C) {
 
71
        s.config.NewWorker = nil
 
72
        s.checkNotValid(c, "nil NewWorker not valid")
 
73
}
 
74
 
 
75
func (s *ManifoldConfigSuite) checkNotValid(c *gc.C, expect string) {
 
76
        err := s.config.Validate()
 
77
        c.Check(err, gc.ErrorMatches, expect)
 
78
        c.Check(err, jc.Satisfies, errors.IsNotValid)
 
79
}