Example #1
0
func (s *APISuite) TestNoCalls(c *gc.C) {
	stub := &testing.Stub{}
	apiCaller := apiCaller(c, nil, nil)
	_, err := singular.NewAPI(apiCaller, machine123)
	c.Check(err, jc.ErrorIsNil)
	stub.CheckCallNames(c)
}
Example #2
0
File: shim.go Project: bac/juju
// NewFacade creates a Facade from an APICaller and a controller. It's a
// suitable default value for ManifoldConfig.NewFacade.
func NewFacade(apiCaller base.APICaller, controllerTag names.MachineTag) (Facade, error) {
	facade, err := singular.NewAPI(apiCaller, controllerTag)
	if err != nil {
		return nil, errors.Trace(err)
	}
	return facade, nil
}
Example #3
0
func (s *APISuite) TestBadControllerTag(c *gc.C) {
	apiCaller := apiCaller(c, nil, nil)
	badTag := names.NewMachineTag("")
	api, err := singular.NewAPI(apiCaller, badTag)
	c.Check(api, gc.IsNil)
	c.Check(err, jc.Satisfies, errors.IsNotValid)
	c.Check(err, gc.ErrorMatches, "controller tag not valid")
}
Example #4
0
func (s *APISuite) TestWaitSuccess(c *gc.C) {
	stub := &testing.Stub{}
	apiCaller := apiCaller(c, stub, func(result *params.ErrorResults) error {
		result.Results = []params.ErrorResult{{}}
		return nil
	})
	api, err := singular.NewAPI(apiCaller, machine123)
	c.Assert(err, jc.ErrorIsNil)

	err = api.Wait()
	c.Check(err, jc.ErrorIsNil)
	checkCall(c, stub, "Wait", params.Entities{
		Entities: []params.Entity{{
			Tag: "model-deadbeef-0bad-400d-8000-4b1d0d06f00d",
		}},
	})
}
Example #5
0
func (s *APISuite) TestClaimSuccess(c *gc.C) {
	stub := &testing.Stub{}
	apiCaller := apiCaller(c, stub, func(result *params.ErrorResults) error {
		result.Results = []params.ErrorResult{{}}
		return nil
	})
	api, err := singular.NewAPI(apiCaller, machine123)
	c.Assert(err, jc.ErrorIsNil)

	err = api.Claim(time.Minute)
	c.Check(err, jc.ErrorIsNil)
	checkCall(c, stub, "Claim", params.SingularClaims{
		Claims: []params.SingularClaim{{
			ModelTag:      "model-deadbeef-0bad-400d-8000-4b1d0d06f00d",
			ControllerTag: "machine-123",
			Duration:      time.Minute,
		}},
	})
}
Example #6
0
func (s *APISuite) TestWaitError(c *gc.C) {
	stub := &testing.Stub{}
	apiCaller := apiCaller(c, stub, func(result *params.ErrorResults) error {
		result.Results = []params.ErrorResult{{
			Error: common.ServerError(errors.New("crunch squelch")),
		}}
		return nil
	})
	api, err := singular.NewAPI(apiCaller, machine123)
	c.Assert(err, jc.ErrorIsNil)

	err = api.Wait()
	c.Check(err, gc.ErrorMatches, "crunch squelch")
	checkCall(c, stub, "Wait", params.Entities{
		Entities: []params.Entity{{
			Tag: "environment-deadbeef-0bad-400d-8000-4b1d0d06f00d",
		}},
	})
}
Example #7
0
func (s *APISuite) TestClaimError(c *gc.C) {
	stub := &testing.Stub{}
	apiCaller := apiCaller(c, stub, func(result *params.ErrorResults) error {
		result.Results = []params.ErrorResult{{
			Error: common.ServerError(errors.New("zap pow splat oof")),
		}}
		return nil
	})
	api, err := singular.NewAPI(apiCaller, machine123)
	c.Assert(err, jc.ErrorIsNil)

	err = api.Claim(time.Second)
	c.Check(err, gc.ErrorMatches, "zap pow splat oof")
	checkCall(c, stub, "Claim", params.SingularClaims{
		Claims: []params.SingularClaim{{
			ModelTag:      "model-deadbeef-0bad-400d-8000-4b1d0d06f00d",
			ControllerTag: "machine-123",
			Duration:      time.Second,
		}},
	})
}
Example #8
0
func (s *APISuite) TestClaimDenied(c *gc.C) {
	stub := &testing.Stub{}
	apiCaller := apiCaller(c, stub, func(result *params.ErrorResults) error {
		result.Results = []params.ErrorResult{{
			Error: common.ServerError(lease.ErrClaimDenied),
		}}
		return nil
	})
	api, err := singular.NewAPI(apiCaller, machine123)
	c.Assert(err, jc.ErrorIsNil)

	err = api.Claim(time.Hour)
	c.Check(err, gc.Equals, lease.ErrClaimDenied)
	checkCall(c, stub, "Claim", params.SingularClaims{
		Claims: []params.SingularClaim{{
			ModelTag:      "environment-deadbeef-0bad-400d-8000-4b1d0d06f00d",
			ControllerTag: "machine-123",
			Duration:      time.Hour,
		}},
	})
}
Example #9
0
func (s *APISuite) TestBadModelTag(c *gc.C) {
	api, err := singular.NewAPI(mockAPICaller{}, machine123)
	c.Check(api, gc.IsNil)
	c.Check(err, gc.ErrorMatches, "no tags for you")
}
Example #10
0
File: api_test.go Project: bac/juju
func (s *APISuite) TestControllerOnlyAPI(c *gc.C) {
	api, err := singular.NewAPI(mockAPICaller{}, machine123)
	c.Check(api, gc.IsNil)
	c.Check(err, gc.ErrorMatches, `cannot use singular API on controller-only connection`)
}