Ejemplo n.º 1
0
func (s *meterStatusWrapperSuite) TestWrapper(c *gc.C) {
	tests := []struct {
		about          string
		input          func() (state.MeterStatus, error)
		expectedOutput state.MeterStatus
	}{{
		about:          "notset in, amber out",
		input:          NotSetGetter,
		expectedOutput: state.MeterStatus{state.MeterAmber, "not set"},
	}, {
		about:          "notavailable in, red out",
		input:          NotAvailableGetter,
		expectedOutput: state.MeterStatus{state.MeterRed, "not available"},
	}, {
		about:          "red in, red out",
		input:          RedGetter,
		expectedOutput: state.MeterStatus{state.MeterRed, "info"},
	}, {
		about:          "green in, green out",
		input:          GreenGetter,
		expectedOutput: state.MeterStatus{state.MeterGreen, "info"},
	}, {
		about:          "amber in, amber out",
		input:          AmberGetter,
		expectedOutput: state.MeterStatus{state.MeterAmber, "info"},
	}}
	for i, test := range tests {
		c.Logf("test %d: %s", i, test.about)
		status, err := meterstatus.MeterStatusWrapper(test.input)
		c.Assert(err, jc.ErrorIsNil)
		c.Assert(status.Code, gc.Equals, test.expectedOutput.Code)
		c.Assert(status.Info, gc.Equals, test.expectedOutput.Info)
	}
}
Ejemplo n.º 2
0
// GetMeterStatus returns meter status information for each unit.
func (u *uniterBaseAPI) GetMeterStatus(args params.Entities) (params.MeterStatusResults, error) {
	result := params.MeterStatusResults{
		Results: make([]params.MeterStatusResult, len(args.Entities)),
	}
	canAccess, err := u.accessUnit()
	if err != nil {
		return params.MeterStatusResults{}, common.ErrPerm
	}
	for i, entity := range args.Entities {
		unitTag, err := names.ParseUnitTag(entity.Tag)
		if err != nil {
			result.Results[i].Error = common.ServerError(common.ErrPerm)
			continue
		}
		err = common.ErrPerm
		var status state.MeterStatus
		if canAccess(unitTag) {
			var unit *state.Unit
			unit, err = u.getUnit(unitTag)
			if err == nil {
				status, err = meterstatus.MeterStatusWrapper(unit.GetMeterStatus)
			}
			result.Results[i].Code = status.Code.String()
			result.Results[i].Info = status.Info
		}
		result.Results[i].Error = common.ServerError(err)
	}
	return result, nil
}
Ejemplo n.º 3
0
func (s *meterStatusWrapperSuite) TestError(c *gc.C) {
	_, err := meterstatus.MeterStatusWrapper(ErrorGetter)
	c.Assert(err, gc.ErrorMatches, "an error")
}