Exemple #1
0
func (s *undertakerSuite) TestRequiresModelConnection(c *gc.C) {
	api, err := machineundertaker.NewAPI(&fakeAPICaller{hasModelTag: false}, nil)
	c.Assert(err, gc.ErrorMatches, "machine undertaker client requires a model API connection")
	c.Assert(api, gc.IsNil)
	api, err = machineundertaker.NewAPI(&fakeAPICaller{hasModelTag: true}, nil)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(api, gc.NotNil)
}
Exemple #2
0
func (*undertakerSuite) TestWatchMachineRemovals_Success(c *gc.C) {
	caller := func(facade string, version int, id, request string, arg, result interface{}) error {
		c.Assert(result, gc.FitsTypeOf, &params.NotifyWatchResults{})
		*result.(*params.NotifyWatchResults) = params.NotifyWatchResults{
			Results: []params.NotifyWatchResult{{
				NotifyWatcherId: "2",
			}},
		}
		return nil
	}
	expectWatcher := &struct{ watcher.NotifyWatcher }{}
	newWatcher := func(wcaller base.APICaller, result params.NotifyWatchResult) watcher.NotifyWatcher {
		c.Check(wcaller, gc.NotNil) // not comparable
		c.Check(result, gc.DeepEquals, params.NotifyWatchResult{
			NotifyWatcherId: "2",
		})
		return expectWatcher
	}

	api, err := machineundertaker.NewAPI(testing.APICallerFunc(caller), newWatcher)
	c.Check(err, jc.ErrorIsNil)
	w, err := api.WatchMachineRemovals()
	c.Check(err, jc.ErrorIsNil)
	c.Check(w, gc.Equals, expectWatcher)
}
Exemple #3
0
// Manifold returns a dependency.Manifold that runs a machine
// undertaker.
func Manifold(config ManifoldConfig) dependency.Manifold {
	return dependency.Manifold{
		Inputs: []string{config.APICallerName, config.EnvironName},
		Start: func(context dependency.Context) (worker.Worker, error) {
			var apiCaller base.APICaller
			if err := context.Get(config.APICallerName, &apiCaller); err != nil {
				return nil, errors.Trace(err)
			}
			var environ environs.Environ
			if err := context.Get(config.EnvironName, &environ); err != nil {
				return nil, errors.Trace(err)
			}
			api, err := machineundertaker.NewAPI(apiCaller, watcher.NewNotifyWatcher)
			if err != nil {
				return nil, errors.Trace(err)
			}
			w, err := config.NewWorker(api, environ)
			if err != nil {
				return nil, errors.Trace(err)
			}
			return w, nil
		},
	}
}
Exemple #4
0
func makeAPI(c *gc.C, caller testing.APICallerFunc) *machineundertaker.API {
	api, err := machineundertaker.NewAPI(caller, nil)
	c.Assert(err, jc.ErrorIsNil)
	return api
}