func (s *DiscoverSpacesSuite) TestNewAPI(c *gc.C) {
	var called int
	apiCaller := clientErrorAPICaller(c, "ListSpaces", nil, &called)
	api := discoverspaces.NewAPI(apiCaller)
	c.Check(api, gc.NotNil)
	c.Check(called, gc.Equals, 0)

	// Make a call so that an error will be returned.
	_, err := api.ListSpaces()
	c.Assert(err, gc.ErrorMatches, "client error!")
	c.Assert(called, gc.Equals, 1)
}
func (s *DiscoverSpacesSuite) TestListSpaces(c *gc.C) {
	var called int
	expectedResult := params.DiscoverSpacesResults{
		Results: []params.ProviderSpace{{Name: "foobar"}},
	}
	apiCaller := successAPICaller(c, "ListSpaces", nil, expectedResult, &called)
	api := discoverspaces.NewAPI(apiCaller)

	result, err := api.ListSpaces()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(result, jc.DeepEquals, expectedResult)
	c.Assert(called, gc.Equals, 1)
}
func (s *DiscoverSpacesSuite) TestModelConfig(c *gc.C) {
	var called int
	cfg, err := config.New(config.UseDefaults, coretesting.FakeConfig())
	c.Assert(err, jc.ErrorIsNil)
	expectedResult := params.ModelConfigResult{
		Config: cfg.AllAttrs(),
	}
	apiCaller := successAPICaller(c, "ModelConfig", nil, expectedResult, &called)
	api := discoverspaces.NewAPI(apiCaller)

	result, err := api.ModelConfig()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(result, jc.DeepEquals, cfg)
	c.Assert(called, gc.Equals, 1)
}
func (s *DiscoverSpacesSuite) TestCreateSpaces(c *gc.C) {
	var called int
	expectedResult := params.ErrorResults{
		Results: []params.ErrorResult{{}},
	}
	expectedArgs := params.CreateSpacesParams{
		Spaces: []params.CreateSpaceParams{{SpaceTag: "foo"}},
	}
	apiCaller := successAPICaller(c, "CreateSpaces", expectedArgs, expectedResult, &called)
	api := discoverspaces.NewAPI(apiCaller)

	result, err := api.CreateSpaces(expectedArgs)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(result, jc.DeepEquals, expectedResult)
	c.Assert(called, gc.Equals, 1)
}
func (s *DiscoverSpacesSuite) TestNewAPIWithNilCaller(c *gc.C) {
	panicFunc := func() { discoverspaces.NewAPI(nil) }
	c.Assert(panicFunc, gc.PanicMatches, "caller is nil")
}
示例#6
0
文件: state.go 项目: makyo/juju
// DiscoverSpaces returns access to the DiscoverSpacesAPI.
func (st *state) DiscoverSpaces() *discoverspaces.API {
	return discoverspaces.NewAPI(st)
}
示例#7
0
文件: manifold.go 项目: bac/juju
func NewFacade(apiCaller base.APICaller) (Facade, error) {
	return discoverspaces.NewAPI(apiCaller), nil
}