Exemplo n.º 1
0
func (s *UnitFacadeSuite) TestGetResourceInfoOkay(c *gc.C) {
	opened1 := resourcetesting.NewResource(c, s.stub, "spam", "a-application", "some data")
	res1 := opened1.Resource
	opened2 := resourcetesting.NewResource(c, s.stub, "eggs", "a-application", "other data")
	res2 := opened2.Resource
	store := &stubUnitDataStore{Stub: s.stub}
	store.ReturnListResources = resource.ServiceResources{
		Resources: []resource.Resource{res1, res2},
	}
	uf := server.UnitFacade{DataStore: store}

	results, err := uf.GetResourceInfo(private.ListResourcesArgs{
		ResourceNames: []string{"spam", "eggs"},
	})
	c.Assert(err, jc.ErrorIsNil)

	s.stub.CheckCallNames(c, "ListResources")
	c.Check(results, jc.DeepEquals, private.ResourcesResult{
		Resources: []private.ResourceResult{{
			Resource: api.Resource2API(res1),
		}, {
			Resource: api.Resource2API(res2),
		}},
	})
}
Exemplo n.º 2
0
func (s *UnitFacadeSuite) TestGetResourceInfoEmpty(c *gc.C) {
	opened := resourcetesting.NewResource(c, s.stub, "spam", "a-application", "some data")
	store := &stubUnitDataStore{Stub: s.stub}
	store.ReturnListResources = resource.ServiceResources{
		Resources: []resource.Resource{opened.Resource},
	}
	uf := server.UnitFacade{DataStore: store}

	results, err := uf.GetResourceInfo(private.ListResourcesArgs{
		ResourceNames: []string{},
	})
	c.Assert(err, jc.ErrorIsNil)

	s.stub.CheckCallNames(c, "ListResources")
	c.Check(results, jc.DeepEquals, private.ResourcesResult{
		Resources: []private.ResourceResult{},
	})
}
Exemplo n.º 3
0
func (s *UnitFacadeSuite) TestGetResourceInfoNotFound(c *gc.C) {
	opened := resourcetesting.NewResource(c, s.stub, "spam", "a-service", "some data")
	store := &stubUnitDataStore{Stub: s.stub}
	store.ReturnListResources = resource.ServiceResources{
		Resources: []resource.Resource{opened.Resource},
	}
	uf := server.UnitFacade{DataStore: store}

	results, err := uf.GetResourceInfo(private.ListResourcesArgs{
		ResourceNames: []string{"eggs"},
	})
	c.Assert(err, jc.ErrorIsNil)

	s.stub.CheckCallNames(c, "ListResources")
	c.Check(results, jc.DeepEquals, private.ResourcesResult{
		Resources: []private.ResourceResult{{
			ErrorResult: params.ErrorResult{
				Error: common.ServerError(errors.NotFoundf(`resource "eggs"`)),
			},
		}},
	})
}