Exemplo n.º 1
0
func (*deadEnsurerSuite) TestEnsureDeadError(c *gc.C) {
	getCanModify := func() (common.AuthFunc, error) {
		return nil, fmt.Errorf("pow")
	}
	d := common.NewDeadEnsurer(&fakeState{}, getCanModify)
	_, err := d.EnsureDead(params.Entities{[]params.Entity{{"x0"}}})
	c.Assert(err, gc.ErrorMatches, "pow")
}
Exemplo n.º 2
0
func (*removeSuite) TestEnsureDeadNoArgsNoError(c *gc.C) {
	getCanModify := func() (common.AuthFunc, error) {
		return nil, fmt.Errorf("pow")
	}
	d := common.NewDeadEnsurer(&fakeState{}, getCanModify)
	result, err := d.EnsureDead(params.Entities{})
	c.Assert(err, gc.IsNil)
	c.Assert(result.Results, gc.HasLen, 0)
}
Exemplo n.º 3
0
// NewUniterAPI creates a new instance of the Uniter API.
func NewUniterAPI(st *state.State, resources *common.Resources, authorizer common.Authorizer) (*UniterAPI, error) {
	if !authorizer.AuthUnitAgent() {
		return nil, common.ErrPerm
	}
	getCanRead := func() (common.AuthFunc, error) {
		return authorizer.AuthOwner, nil
	}
	return &UniterAPI{
		LifeGetter:         common.NewLifeGetter(st, getCanRead),
		StatusSetter:       common.NewStatusSetter(st, getCanRead),
		DeadEnsurer:        common.NewDeadEnsurer(st, getCanRead),
		AgentEntityWatcher: common.NewAgentEntityWatcher(st, resources, getCanRead),
		st:                 st,
		auth:               authorizer,
	}, nil
}
Exemplo n.º 4
0
func (*deadEnsurerSuite) TestEnsureDead(c *gc.C) {
	st := &fakeState{
		entities: map[string]entityWithError{
			"x0": &fakeDeadEnsurer{life: state.Dying, err: fmt.Errorf("x0 fails")},
			"x1": &fakeDeadEnsurer{life: state.Alive},
			"x2": &fakeDeadEnsurer{life: state.Dying},
			"x3": &fakeDeadEnsurer{life: state.Dead},
			"x4": &fakeDeadEnsurer{fetchError: "x4 error"},
		},
	}
	getCanModify := func() (common.AuthFunc, error) {
		return func(tag string) bool {
			switch tag {
			case "x0", "x1", "x2", "x4":
				return true
			}
			return false
		}, nil
	}
	d := common.NewDeadEnsurer(st, getCanModify)
	entities := params.Entities{[]params.Entity{
		{"x0"}, {"x1"}, {"x2"}, {"x3"}, {"x4"}, {"x5"},
	}}
	result, err := d.EnsureDead(entities)
	c.Assert(err, gc.IsNil)
	c.Assert(result, gc.DeepEquals, params.ErrorResults{
		Results: []params.ErrorResult{
			{&params.Error{Message: "x0 fails"}},
			{nil},
			{nil},
			{apiservertesting.ErrUnauthorized},
			{&params.Error{Message: "x4 error"}},
			{apiservertesting.ErrUnauthorized},
		},
	})
}