Example #1
0
func (*FacadeSuite) TestLifeSuccess(c *gc.C) {
	backend := &mockBackend{exist: true}
	facade, err := lifeflag.NewFacade(backend, nil, auth(true))
	c.Check(err, jc.ErrorIsNil)

	results, err := facade.Life(modelEntity())
	c.Check(err, jc.ErrorIsNil)
	c.Check(results, jc.DeepEquals, params.LifeResults{
		Results: []params.LifeResult{{Life: params.Dying}},
	})
}
Example #2
0
func (*FacadeSuite) TestWatchAuthFailure(c *gc.C) {
	backend := &mockBackend{}
	facade, err := lifeflag.NewFacade(backend, nil, auth(true))
	c.Assert(err, jc.ErrorIsNil)

	results, err := facade.Watch(entities("unit-foo-1"))
	c.Check(err, jc.ErrorIsNil)
	c.Assert(results.Results, gc.HasLen, 1)
	result := results.Results[0]
	c.Check(result.NotifyWatcherId, gc.Equals, "")
	c.Check(result.Error, jc.Satisfies, params.IsCodeUnauthorized)
}
Example #3
0
func (*FacadeSuite) TestLifeNotFound(c *gc.C) {
	backend := &mockBackend{}
	facade, err := lifeflag.NewFacade(backend, nil, auth(true))
	c.Assert(err, jc.ErrorIsNil)

	results, err := facade.Life(modelEntity())
	c.Check(err, jc.ErrorIsNil)
	c.Assert(results.Results, gc.HasLen, 1)
	result := results.Results[0]
	c.Check(result.Life, gc.Equals, params.Life(""))
	c.Check(result.Error, jc.Satisfies, params.IsCodeNotFound)
}
Example #4
0
func (*FacadeSuite) TestWatchSuccess(c *gc.C) {
	backend := &mockBackend{exist: true, watch: true}
	resources := common.NewResources()
	facade, err := lifeflag.NewFacade(backend, resources, auth(true))
	c.Check(err, jc.ErrorIsNil)

	results, err := facade.Watch(modelEntity())
	c.Check(err, jc.ErrorIsNil)
	c.Check(results, jc.DeepEquals, params.NotifyWatchResults{
		Results: []params.NotifyWatchResult{{NotifyWatcherId: "1"}},
	})
}
Example #5
0
func (*FacadeSuite) TestWatchBadWatcher(c *gc.C) {
	backend := &mockBackend{exist: true}
	facade, err := lifeflag.NewFacade(backend, nil, auth(true))
	c.Check(err, jc.ErrorIsNil)

	results, err := facade.Watch(modelEntity())
	c.Check(err, jc.ErrorIsNil)
	c.Assert(results.Results, gc.HasLen, 1)
	result := results.Results[0]
	c.Check(result.NotifyWatcherId, gc.Equals, "")
	c.Check(result.Error, gc.ErrorMatches, "blammo")
}
Example #6
0
func (*FacadeSuite) TestWatchBadEntity(c *gc.C) {
	backend := &mockBackend{}
	facade, err := lifeflag.NewFacade(backend, nil, auth(true))
	c.Assert(err, jc.ErrorIsNil)

	results, err := facade.Watch(entities("archibald snookums"))
	c.Check(err, jc.ErrorIsNil)
	c.Assert(results.Results, gc.HasLen, 1)
	result := results.Results[0]
	c.Check(result.NotifyWatcherId, gc.Equals, "")

	// TODO(fwereade): this is DUMB. should just be a parse error.
	// but I'm not fixing the underlying implementation as well.
	c.Check(result.Error, jc.Satisfies, params.IsCodeUnauthorized)
}
Example #7
0
func (*FacadeSuite) TestFacadeAuthFailure(c *gc.C) {
	facade, err := lifeflag.NewFacade(nil, nil, auth(false))
	c.Check(facade, gc.IsNil)
	c.Check(err, gc.Equals, common.ErrPerm)
}