func (s *inventorySuite) TestSetStatus(c *C) { ctrl := gomock.NewController(c) defer ctrl.Finish() mClient := mock.NewMockSubsysClient(ctrl) asset := &Asset{ client: mClient, name: "foo", status: Unallocated, prevStatus: Incomplete, state: Discovered, prevState: Unknown, } eAsset := &Asset{ client: mClient, name: "foo", status: Provisioning, prevStatus: Unallocated, state: Disappeared, prevState: Discovered, } mClient.EXPECT().SetAssetStatus(asset.name, eAsset.status.String(), eAsset.state.String(), StateDescription[eAsset.state]) err := asset.SetStatus(eAsset.status, eAsset.state) c.Assert(err, IsNil) c.Assert(asset, DeepEquals, eAsset) }
func (s *inventorySuite) TestSetStatusSetFailure(c *C) { ctrl := gomock.NewController(c) defer ctrl.Finish() mClient := mock.NewMockSubsysClient(ctrl) asset := &Asset{ client: mClient, name: "foo", status: Unallocated, prevStatus: Incomplete, state: Discovered, prevState: Unknown, } eAsset := &Asset{ client: mClient, name: "foo", status: Unallocated, prevStatus: Incomplete, state: Discovered, prevState: Unknown, } mClient.EXPECT().SetAssetStatus(asset.name, Provisioning.String(), Discovered.String(), StateDescription[asset.state]).Return(errored.Errorf("test failure")) err := asset.SetStatus(Provisioning, Discovered) c.Assert(err, NotNil) c.Assert(asset, DeepEquals, eAsset) }
func (s *inventorySuite) TestNewAssetCreateFailure(c *C) { ctrl := gomock.NewController(c) defer ctrl.Finish() mClient := mock.NewMockSubsysClient(ctrl) eAsset := &Asset{ client: mClient, name: "foo", status: Unallocated, prevStatus: Incomplete, state: Discovered, prevState: Unknown, } mClient.EXPECT().CreateAsset(eAsset.name, eAsset.status.String()).Return(errored.Errorf("test error")) _, err := NewAsset(mClient, eAsset.name) c.Assert(err, NotNil) }