1
// Copyright 2016 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
4
package migrationmaster_test
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"
13
"github.com/juju/juju/api/base"
14
"github.com/juju/juju/worker"
15
"github.com/juju/juju/worker/migrationmaster"
18
type ManifoldConfigSuite struct {
19
testing.IsolationSuite
20
config migrationmaster.ManifoldConfig
23
var _ = gc.Suite(&ManifoldConfigSuite{})
25
func (s *ManifoldConfigSuite) SetUpTest(c *gc.C) {
26
s.IsolationSuite.SetUpTest(c)
27
s.config = s.validConfig()
30
func (s *ManifoldConfigSuite) validConfig() migrationmaster.ManifoldConfig {
31
return migrationmaster.ManifoldConfig{
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 },
41
func (s *ManifoldConfigSuite) TestValid(c *gc.C) {
42
c.Check(s.config.Validate(), jc.ErrorIsNil)
45
func (s *ManifoldConfigSuite) TestMissingAgentName(c *gc.C) {
46
s.config.AgentName = ""
47
s.checkNotValid(c, "empty AgentName not valid")
50
func (s *ManifoldConfigSuite) TestMissingAPICallerName(c *gc.C) {
51
s.config.APICallerName = ""
52
s.checkNotValid(c, "empty APICallerName not valid")
55
func (s *ManifoldConfigSuite) TestMissingFortressName(c *gc.C) {
56
s.config.FortressName = ""
57
s.checkNotValid(c, "empty FortressName not valid")
60
func (s *ManifoldConfigSuite) TestMissingClock(c *gc.C) {
62
s.checkNotValid(c, "nil Clock not valid")
65
func (s *ManifoldConfigSuite) TestMissingNewFacade(c *gc.C) {
66
s.config.NewFacade = nil
67
s.checkNotValid(c, "nil NewFacade not valid")
70
func (s *ManifoldConfigSuite) TestMissingNewWorker(c *gc.C) {
71
s.config.NewWorker = nil
72
s.checkNotValid(c, "nil NewWorker not valid")
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)