コード例 #1
0
ファイル: facade_test.go プロジェクト: makyo/juju
func (*FacadeSuite) TestWatchSuccess(c *gc.C) {
	stub := &testing.Stub{}
	backend := newMockBackend(stub)
	resources := common.NewResources()
	facade, err := migrationflag.New(backend, resources, authOK)
	c.Assert(err, jc.ErrorIsNil)

	results := facade.Watch(entities(
		coretesting.ModelTag.String(),
		coretesting.ModelTag.String(),
	))
	c.Assert(results.Results, gc.HasLen, 2)
	stub.CheckCallNames(c, "WatchMigrationPhase", "WatchMigrationPhase")

	check := func(result params.NotifyWatchResult) {
		c.Check(result.Error, gc.IsNil)
		resource := resources.Get(result.NotifyWatcherId)
		c.Check(resource, gc.NotNil)
	}
	first := results.Results[0]
	second := results.Results[1]
	check(first)
	check(second)
	c.Check(first.NotifyWatcherId, gc.Not(gc.Equals), second.NotifyWatcherId)
}
コード例 #2
0
ファイル: facade_test.go プロジェクト: makyo/juju
func (*FacadeSuite) TestPhaseErrors(c *gc.C) {
	stub := &testing.Stub{}
	stub.SetErrors(errors.New("ouch"))
	backend := newMockBackend(stub)
	facade, err := migrationflag.New(backend, nil, authOK)
	c.Assert(err, jc.ErrorIsNil)

	// 3 entities: unparseable, unauthorized, call error.
	results := facade.Phase(entities(
		"urgle",
		unknownModel,
		coretesting.ModelTag.String(),
	))
	c.Assert(results.Results, gc.HasLen, 3)
	stub.CheckCallNames(c, "MigrationPhase")

	c.Check(results.Results, jc.DeepEquals, []params.PhaseResult{{
		Error: &params.Error{
			Message: `"urgle" is not a valid tag`,
		}}, {
		Error: &params.Error{
			Message: "permission denied",
			Code:    "unauthorized access",
		}}, {
		Error: &params.Error{
			Message: "ouch",
		},
	}})
}
コード例 #3
0
ファイル: facade_test.go プロジェクト: makyo/juju
func (*FacadeSuite) TestWatchErrors(c *gc.C) {
	stub := &testing.Stub{}
	stub.SetErrors(errors.New("blort"), nil, errors.New("squish"))
	backend := newMockBackend(stub)
	resources := common.NewResources()
	facade, err := migrationflag.New(backend, resources, authOK)
	c.Assert(err, jc.ErrorIsNil)

	// 4 entities: unparseable, unauthorized, watch error, closed chan.
	results := facade.Watch(entities(
		"urgle",
		unknownModel,
		coretesting.ModelTag.String(),
		coretesting.ModelTag.String(),
	))
	c.Assert(results.Results, gc.HasLen, 4)
	stub.CheckCallNames(c, "WatchMigrationPhase", "WatchMigrationPhase")

	c.Check(results.Results, jc.DeepEquals, []params.NotifyWatchResult{{
		Error: &params.Error{
			Message: `"urgle" is not a valid tag`,
		}}, {
		Error: &params.Error{
			Message: "permission denied",
			Code:    "unauthorized access",
		}}, {
		Error: &params.Error{
			Message: "blort",
		}}, {
		Error: &params.Error{
			Message: "squish",
		},
	}})
	c.Check(resources.Count(), gc.Equals, 0)
}
コード例 #4
0
ファイル: facade_test.go プロジェクト: makyo/juju
func (*FacadeSuite) TestPhaseSuccess(c *gc.C) {
	stub := &testing.Stub{}
	backend := newMockBackend(stub)
	facade, err := migrationflag.New(backend, nil, authOK)
	c.Assert(err, jc.ErrorIsNil)

	results := facade.Phase(entities(
		coretesting.ModelTag.String(),
		coretesting.ModelTag.String(),
	))
	c.Assert(results.Results, gc.HasLen, 2)
	stub.CheckCallNames(c, "MigrationPhase", "MigrationPhase")

	for _, result := range results.Results {
		c.Check(result.Error, gc.IsNil)
		c.Check(result.Phase, gc.Equals, "REAP")
	}
}
コード例 #5
0
ファイル: facade_test.go プロジェクト: makyo/juju
func (*FacadeSuite) TestRejectsNonAgent(c *gc.C) {
	facade, err := migrationflag.New(nil, nil, agentAuth{})
	c.Check(err, gc.Equals, common.ErrPerm)
	c.Check(facade, gc.IsNil)
}
コード例 #6
0
ファイル: facade_test.go プロジェクト: makyo/juju
func (*FacadeSuite) TestAcceptsUnitAgent(c *gc.C) {
	facade, err := migrationflag.New(nil, nil, agentAuth{machine: true})
	c.Check(err, jc.ErrorIsNil)
	c.Check(facade, gc.NotNil)
}