1
// Copyright 2016 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
4
package applicationscaler_test
7
"github.com/juju/errors"
8
"github.com/juju/testing"
9
jc "github.com/juju/testing/checkers"
10
gc "gopkg.in/check.v1"
12
"github.com/juju/juju/api/base"
13
"github.com/juju/juju/worker"
14
"github.com/juju/juju/worker/applicationscaler"
15
"github.com/juju/juju/worker/dependency"
16
dt "github.com/juju/juju/worker/dependency/testing"
19
type ManifoldSuite struct {
20
testing.IsolationSuite
23
var _ = gc.Suite(&ManifoldSuite{})
25
func (s *ManifoldSuite) TestInputs(c *gc.C) {
26
manifold := applicationscaler.Manifold(applicationscaler.ManifoldConfig{
27
APICallerName: "washington the terrible",
29
c.Check(manifold.Inputs, jc.DeepEquals, []string{"washington the terrible"})
32
func (s *ManifoldSuite) TestOutput(c *gc.C) {
33
manifold := applicationscaler.Manifold(applicationscaler.ManifoldConfig{})
34
c.Check(manifold.Output, gc.IsNil)
37
func (s *ManifoldSuite) TestStartMissingAPICaller(c *gc.C) {
38
manifold := applicationscaler.Manifold(applicationscaler.ManifoldConfig{
39
APICallerName: "api-caller",
41
context := dt.StubContext(nil, map[string]interface{}{
42
"api-caller": dependency.ErrMissing,
45
worker, err := manifold.Start(context)
46
c.Check(errors.Cause(err), gc.Equals, dependency.ErrMissing)
47
c.Check(worker, gc.IsNil)
50
func (s *ManifoldSuite) TestStartFacadeError(c *gc.C) {
51
expectCaller := &fakeCaller{}
52
manifold := applicationscaler.Manifold(applicationscaler.ManifoldConfig{
53
APICallerName: "api-caller",
54
NewFacade: func(apiCaller base.APICaller) (applicationscaler.Facade, error) {
55
c.Check(apiCaller, gc.Equals, expectCaller)
56
return nil, errors.New("blort")
59
context := dt.StubContext(nil, map[string]interface{}{
60
"api-caller": expectCaller,
63
worker, err := manifold.Start(context)
64
c.Check(err, gc.ErrorMatches, "blort")
65
c.Check(worker, gc.IsNil)
68
func (s *ManifoldSuite) TestStartWorkerError(c *gc.C) {
69
expectFacade := &fakeFacade{}
70
manifold := applicationscaler.Manifold(applicationscaler.ManifoldConfig{
71
APICallerName: "api-caller",
72
NewFacade: func(_ base.APICaller) (applicationscaler.Facade, error) {
73
return expectFacade, nil
75
NewWorker: func(config applicationscaler.Config) (worker.Worker, error) {
76
c.Check(config.Validate(), jc.ErrorIsNil)
77
c.Check(config.Facade, gc.Equals, expectFacade)
78
return nil, errors.New("splot")
81
context := dt.StubContext(nil, map[string]interface{}{
82
"api-caller": &fakeCaller{},
85
worker, err := manifold.Start(context)
86
c.Check(err, gc.ErrorMatches, "splot")
87
c.Check(worker, gc.IsNil)
90
func (s *ManifoldSuite) TestSuccess(c *gc.C) {
91
expectWorker := &fakeWorker{}
92
manifold := applicationscaler.Manifold(applicationscaler.ManifoldConfig{
93
APICallerName: "api-caller",
94
NewFacade: func(_ base.APICaller) (applicationscaler.Facade, error) {
95
return &fakeFacade{}, nil
97
NewWorker: func(_ applicationscaler.Config) (worker.Worker, error) {
98
return expectWorker, nil
101
context := dt.StubContext(nil, map[string]interface{}{
102
"api-caller": &fakeCaller{},
105
worker, err := manifold.Start(context)
106
c.Check(err, jc.ErrorIsNil)
107
c.Check(worker, gc.Equals, expectWorker)
110
type fakeCaller struct {
114
type fakeFacade struct {
115
applicationscaler.Facade
118
type fakeWorker struct {