Ejemplo n.º 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)
}
Ejemplo n.º 2
0
Archivo: shim.go Proyecto: 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
}
Ejemplo n.º 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")
}
Ejemplo n.º 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",
		}},
	})
}
Ejemplo n.º 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,
		}},
	})
}
Ejemplo n.º 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",
		}},
	})
}
Ejemplo n.º 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,
		}},
	})
}
Ejemplo n.º 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,
		}},
	})
}
Ejemplo n.º 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")
}
Ejemplo n.º 10
0
Archivo: api_test.go Proyecto: 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`)
}