예제 #1
0
파일: facade_test.go 프로젝트: bac/juju
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")
}
예제 #2
0
파일: facade_test.go 프로젝트: bac/juju
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")
}
예제 #3
0
파일: facade_test.go 프로젝트: bac/juju
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")
}
예제 #4
0
파일: facade_test.go 프로젝트: bac/juju
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")
}
예제 #5
0
파일: facade_test.go 프로젝트: bac/juju
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")
}
예제 #6
0
파일: facade_test.go 프로젝트: bac/juju
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")
}
예제 #7
0
파일: facade_test.go 프로젝트: bac/juju
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")
}
예제 #8
0
파일: facade_test.go 프로젝트: bac/juju
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")
}
예제 #9
0
파일: facade_test.go 프로젝트: bac/juju
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")
}
예제 #10
0
파일: facade_test.go 프로젝트: bac/juju
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")
}
예제 #11
0
파일: shim.go 프로젝트: 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
}