Ejemplo n.º 1
0
func (*FacadeSuite) TestWatchSuccess(c *gc.C) {
	stub := &testing.Stub{}
	apiCaller := apiCaller(c, stub, func(response interface{}) error {
		outPtr, ok := response.(*params.NotifyWatchResults)
		c.Assert(ok, jc.IsTrue)
		outPtr.Results = []params.NotifyWatchResult{
			{NotifyWatcherId: "789"},
		}
		return nil
	})
	expectWatch := &struct{ watcher.NotifyWatcher }{}
	newWatcher := func(gotCaller base.APICaller, result params.NotifyWatchResult) watcher.NotifyWatcher {
		c.Check(gotCaller, gc.NotNil) // uncomparable
		c.Check(result, jc.DeepEquals, params.NotifyWatchResult{
			NotifyWatcherId: "789",
		})
		return expectWatch
	}
	facade := migrationflag.NewFacade(apiCaller, newWatcher)

	watch, err := facade.Watch(someUUID)
	c.Check(err, jc.ErrorIsNil)
	c.Check(watch, gc.Equals, expectWatch)
	checkCalls(c, stub, "Watch")
}
Ejemplo n.º 2
0
func (*FacadeSuite) TestPhaseNoResults(c *gc.C) {
	stub := &testing.Stub{}
	apiCaller := apiCaller(c, stub, func(interface{}) error {
		return nil
	})
	facade := migrationflag.NewFacade(apiCaller, nil)

	phase, err := facade.Phase(someUUID)
	c.Check(err, gc.ErrorMatches, "expected 1 result, got 0")
	c.Check(phase, gc.Equals, migration.UNKNOWN)
	checkCalls(c, stub, "Phase")
}
Ejemplo n.º 3
0
func (*FacadeSuite) TestPhaseCallError(c *gc.C) {
	stub := &testing.Stub{}
	apiCaller := apiCaller(c, stub, func(interface{}) error {
		return errors.New("bork")
	})
	facade := migrationflag.NewFacade(apiCaller, nil)

	phase, err := facade.Phase(someUUID)
	c.Check(err, gc.ErrorMatches, "bork")
	c.Check(phase, gc.Equals, migration.UNKNOWN)
	checkCalls(c, stub, "Phase")
}
Ejemplo n.º 4
0
func (*FacadeSuite) TestWatchNoResults(c *gc.C) {
	stub := &testing.Stub{}
	apiCaller := apiCaller(c, stub, func(interface{}) error {
		return nil
	})
	facade := migrationflag.NewFacade(apiCaller, nil)

	watch, err := facade.Watch(someUUID)
	c.Check(err, gc.ErrorMatches, "expected 1 result, got 0")
	c.Check(watch, gc.IsNil)
	checkCalls(c, stub, "Watch")
}
Ejemplo n.º 5
0
func (*FacadeSuite) TestWatchCallError(c *gc.C) {
	stub := &testing.Stub{}
	apiCaller := apiCaller(c, stub, func(interface{}) error {
		return errors.New("bork")
	})
	facade := migrationflag.NewFacade(apiCaller, nil)

	watch, err := facade.Watch(someUUID)
	c.Check(err, gc.ErrorMatches, "bork")
	c.Check(watch, gc.IsNil)
	checkCalls(c, stub, "Watch")
}
Ejemplo n.º 6
0
func (*FacadeSuite) TestPhaseInvalid(c *gc.C) {
	stub := &testing.Stub{}
	apiCaller := apiCaller(c, stub, func(response interface{}) error {
		outPtr, ok := response.(*params.PhaseResults)
		c.Assert(ok, jc.IsTrue)
		outPtr.Results = []params.PhaseResult{{Phase: "COLLABORATE"}}
		return nil
	})
	facade := migrationflag.NewFacade(apiCaller, nil)

	phase, err := facade.Phase(someUUID)
	c.Check(err, gc.ErrorMatches, `unknown phase "COLLABORATE"`)
	c.Check(phase, gc.Equals, migration.UNKNOWN)
	checkCalls(c, stub, "Phase")
}
Ejemplo n.º 7
0
func (*FacadeSuite) TestPhaseSuccess(c *gc.C) {
	stub := &testing.Stub{}
	apiCaller := apiCaller(c, stub, func(response interface{}) error {
		outPtr, ok := response.(*params.PhaseResults)
		c.Assert(ok, jc.IsTrue)
		outPtr.Results = []params.PhaseResult{{Phase: "ABORT"}}
		return nil
	})
	facade := migrationflag.NewFacade(apiCaller, nil)

	phase, err := facade.Phase(someUUID)
	c.Check(err, jc.ErrorIsNil)
	c.Check(phase, gc.Equals, migration.ABORT)
	checkCalls(c, stub, "Phase")
}
Ejemplo n.º 8
0
func (*FacadeSuite) TestPhaseError(c *gc.C) {
	stub := &testing.Stub{}
	apiCaller := apiCaller(c, stub, func(response interface{}) error {
		outPtr, ok := response.(*params.PhaseResults)
		c.Assert(ok, jc.IsTrue)
		outPtr.Results = []params.PhaseResult{
			{Error: &params.Error{Message: "mneh"}},
		}
		return nil
	})
	facade := migrationflag.NewFacade(apiCaller, nil)

	phase, err := facade.Phase(someUUID)
	c.Check(err, gc.ErrorMatches, "mneh")
	c.Check(phase, gc.Equals, migration.UNKNOWN)
	checkCalls(c, stub, "Phase")
}
Ejemplo n.º 9
0
func (*FacadeSuite) TestWatchError(c *gc.C) {
	stub := &testing.Stub{}
	apiCaller := apiCaller(c, stub, func(response interface{}) error {
		outPtr, ok := response.(*params.NotifyWatchResults)
		c.Assert(ok, jc.IsTrue)
		outPtr.Results = []params.NotifyWatchResult{
			{Error: &params.Error{Message: "snfl"}},
		}
		return nil
	})
	facade := migrationflag.NewFacade(apiCaller, nil)

	watch, err := facade.Watch(someUUID)
	c.Check(err, gc.ErrorMatches, "snfl")
	c.Check(watch, gc.IsNil)
	checkCalls(c, stub, "Watch")
}
Ejemplo n.º 10
0
func (*FacadeSuite) TestWatchExtraResults(c *gc.C) {
	stub := &testing.Stub{}
	apiCaller := apiCaller(c, stub, func(response interface{}) error {
		outPtr, ok := response.(*params.NotifyWatchResults)
		c.Assert(ok, jc.IsTrue)
		outPtr.Results = []params.NotifyWatchResult{
			{NotifyWatcherId: "123"},
			{NotifyWatcherId: "456"},
		}
		return nil
	})
	facade := migrationflag.NewFacade(apiCaller, nil)

	watch, err := facade.Watch(someUUID)
	c.Check(err, gc.ErrorMatches, "expected 1 result, got 2")
	c.Check(watch, gc.IsNil)
	checkCalls(c, stub, "Watch")
}
Ejemplo n.º 11
0
Archivo: shim.go Proyecto: bac/juju
// NewFacade creates a *migrationflag.Facade and returns it as a Facade.
func NewFacade(apiCaller base.APICaller) (Facade, error) {
	facade := migrationflag.NewFacade(apiCaller, watcher.NewNotifyWatcher)
	return facade, nil
}