Exemple #1
0
func (s *APISuite) TestRescaleCallError(c *gc.C) {
	caller := apiCaller(c, func(_ string, _, _ interface{}) error {
		return errors.New("snorble flip")
	})
	api := applicationscaler.NewAPI(caller, nil)

	err := api.Rescale(nil)
	c.Check(err, gc.ErrorMatches, "snorble flip")
}
Exemple #2
0
func (s *APISuite) TestRescaleNoError(c *gc.C) {
	caller := apiCaller(c, func(_ string, _, _ interface{}) error {
		return nil
	})
	api := applicationscaler.NewAPI(caller, nil)

	err := api.Rescale(nil)
	c.Check(err, jc.ErrorIsNil)
}
Exemple #3
0
func (s *APISuite) TestRescaleBadArgs(c *gc.C) {
	caller := apiCaller(c, func(_ string, _, _ interface{}) error {
		panic("should not be called")
	})
	api := applicationscaler.NewAPI(caller, nil)

	err := api.Rescale([]string{"good-name", "bad/name"})
	c.Check(err, gc.ErrorMatches, `application name "bad/name" not valid`)
	c.Check(err, jc.Satisfies, errors.IsNotValid)
}
Exemple #4
0
func (s *APISuite) TestRescaleMethodName(c *gc.C) {
	var called bool
	caller := apiCaller(c, func(request string, _, _ interface{}) error {
		called = true
		c.Check(request, gc.Equals, "Rescale")
		return nil
	})
	api := applicationscaler.NewAPI(caller, nil)

	api.Rescale(nil)
	c.Check(called, jc.IsTrue)
}
Exemple #5
0
func (s *APISuite) TestWatchMethodName(c *gc.C) {
	var called bool
	caller := apiCaller(c, func(request string, _, _ interface{}) error {
		called = true
		c.Check(request, gc.Equals, "Watch")
		return errors.New("irrelevant")
	})
	api := applicationscaler.NewAPI(caller, nil)

	api.Watch()
	c.Check(called, jc.IsTrue)
}
Exemple #6
0
func (s *APISuite) TestWatchError(c *gc.C) {
	var called bool
	caller := apiCaller(c, func(request string, _, _ interface{}) error {
		called = true
		c.Check(request, gc.Equals, "Watch")
		return errors.New("blam pow")
	})
	api := applicationscaler.NewAPI(caller, nil)

	watcher, err := api.Watch()
	c.Check(watcher, gc.IsNil)
	c.Check(err, gc.ErrorMatches, "blam pow")
	c.Check(called, jc.IsTrue)
}
Exemple #7
0
func (s *APISuite) TestRescaleConvertArgs(c *gc.C) {
	var called bool
	caller := apiCaller(c, func(_ string, arg, _ interface{}) error {
		called = true
		c.Check(arg, gc.DeepEquals, params.Entities{
			Entities: []params.Entity{{
				"application-foo",
			}, {
				"application-bar-baz",
			}},
		})
		return nil
	})
	api := applicationscaler.NewAPI(caller, nil)

	api.Rescale([]string{"foo", "bar-baz"})
	c.Check(called, jc.IsTrue)
}
Exemple #8
0
func (s *APISuite) TestRescaleFirstError(c *gc.C) {
	caller := apiCaller(c, func(_ string, _, result interface{}) error {
		resultPtr, ok := result.(*params.ErrorResults)
		c.Assert(ok, jc.IsTrue)
		*resultPtr = params.ErrorResults{Results: []params.ErrorResult{{
			nil,
		}, {
			&params.Error{Message: "expect this error"},
		}, {
			&params.Error{Message: "not this one"},
		}, {
			nil,
		}}}
		return nil
	})
	api := applicationscaler.NewAPI(caller, nil)

	err := api.Rescale(nil)
	c.Check(err, gc.ErrorMatches, "expect this error")
}
Exemple #9
0
func (s *APISuite) TestWatchSuccess(c *gc.C) {
	expectResult := params.StringsWatchResult{
		StringsWatcherId: "123",
		Changes:          []string{"ping", "pong", "pung"},
	}
	caller := apiCaller(c, func(_ string, _, result interface{}) error {
		resultPtr, ok := result.(*params.StringsWatchResult)
		c.Assert(ok, jc.IsTrue)
		*resultPtr = expectResult
		return nil
	})
	expectWatcher := &stubWatcher{}
	newWatcher := func(gotCaller base.APICaller, gotResult params.StringsWatchResult) watcher.StringsWatcher {
		c.Check(gotCaller, gc.NotNil) // uncomparable
		c.Check(gotResult, jc.DeepEquals, expectResult)
		return expectWatcher
	}
	api := applicationscaler.NewAPI(caller, newWatcher)

	watcher, err := api.Watch()
	c.Check(watcher, gc.Equals, expectWatcher)
	c.Check(err, jc.ErrorIsNil)
}
Exemple #10
0
Fichier : shim.go Projet : bac/juju
// NewFacade creates a Facade from a base.APICaller.
// It's a sensible value for ManifoldConfig.NewFacade.
func NewFacade(apiCaller base.APICaller) (Facade, error) {
	return applicationscaler.NewAPI(
		apiCaller,
		watcher.NewStringsWatcher,
	), nil
}