Пример #1
0
func (s *suite) TestSetStatus(c *gc.C) {
	id := "ce5bc2a7-65d8-4800-8199-a7c3356ab309"
	s.state.stateIDs = []string{id}
	s.state.stateIDs = []string{"ce5bc2a7-65d8-4800-8199-a7c3356ab309"}

	a := UnitFacade{s.state}
	args := internal.SetStatusArgs{
		Args: []internal.SetStatusArg{{
			Entity: params.Entity{
				Tag: names.NewPayloadTag(id).String(),
			},
			Status: payload.StateRunning,
		}},
	}
	res, err := a.SetStatus(args)
	c.Assert(err, jc.ErrorIsNil)

	c.Check(s.state.id, gc.Equals, id)
	c.Assert(s.state.status, gc.Equals, payload.StateRunning)

	expected := internal.PayloadResults{
		Results: []internal.PayloadResult{{
			Entity: params.Entity{
				Tag: names.NewPayloadTag(id).String(),
			},
			Error: nil,
		}},
	}
	c.Assert(res, gc.DeepEquals, expected)
}
Пример #2
0
func (s *suite) TestUntrack(c *gc.C) {
	id := "ce5bc2a7-65d8-4800-8199-a7c3356ab309"
	s.state.stateIDs = []string{id}

	a := UnitFacade{s.state}
	args := params.Entities{
		Entities: []params.Entity{{
			Tag: names.NewPayloadTag(id).String(),
		}},
	}
	res, err := a.Untrack(args)
	c.Assert(err, jc.ErrorIsNil)

	c.Assert(s.state.id, gc.Equals, id)

	expected := internal.PayloadResults{
		Results: []internal.PayloadResult{{
			Entity: params.Entity{
				Tag: names.NewPayloadTag(id).String(),
			},
			Error: nil,
		}},
	}
	c.Assert(res, gc.DeepEquals, expected)
}
Пример #3
0
func (s *suite) TestListOne(c *gc.C) {
	id := "ce5bc2a7-65d8-4800-8199-a7c3356ab309"
	pl := payload.Payload{
		PayloadClass: charm.PayloadClass{
			Name: "foobar",
			Type: "type",
		},
		ID:     "idfoo",
		Status: payload.StateRunning,
		Unit:   "a-service/0",
	}
	s.state.payloads = []payload.Result{{
		ID: id,
		Payload: &payload.FullPayloadInfo{
			Payload: pl,
			Machine: "1",
		},
	}}

	a := UnitFacade{s.state}
	args := params.Entities{
		Entities: []params.Entity{{
			Tag: names.NewPayloadTag(id).String(),
		}},
	}
	results, err := a.List(args)
	c.Assert(err, jc.ErrorIsNil)

	expected := api.Payload{
		Class:   "foobar",
		Type:    "type",
		ID:      "idfoo",
		Status:  payload.StateRunning,
		Labels:  []string{},
		Unit:    "unit-a-service-0",
		Machine: "machine-1",
	}

	c.Check(results, jc.DeepEquals, internal.PayloadResults{
		Results: []internal.PayloadResult{{
			Entity: params.Entity{
				Tag: names.NewPayloadTag(id).String(),
			},
			Payload:  &expected,
			NotFound: false,
			Error:    nil,
		}},
	})
}
Пример #4
0
func (s *suite) TestLookUpMixed(c *gc.C) {
	s.state.stateIDs = []string{
		"ce5bc2a7-65d8-4800-8199-a7c3356ab309",
		"",
		"ce5bc2a7-65d8-4800-8199-a7c3356ab311",
	}
	notFound := errors.NotFoundf("payload")
	s.stub.SetErrors(nil, notFound, nil)

	a := UnitFacade{s.state}
	args := internal.LookUpArgs{
		Args: []internal.LookUpArg{{
			Name: "fooID",
			ID:   "bar",
		}, {
			Name: "bazID",
			ID:   "bam",
		}, {
			Name: "spam",
			ID:   "eggs",
		}},
	}
	res, err := a.LookUp(args)
	c.Assert(err, jc.ErrorIsNil)

	s.stub.CheckCallNames(c, "LookUp", "LookUp", "LookUp")
	c.Check(res, jc.DeepEquals, internal.PayloadResults{
		Results: []internal.PayloadResult{{
			Entity: params.Entity{
				Tag: names.NewPayloadTag("ce5bc2a7-65d8-4800-8199-a7c3356ab309").String(),
			},
			NotFound: false,
			Error:    nil,
		}, {
			Entity: params.Entity{
				Tag: "",
			},
			NotFound: true,
			Error:    common.ServerError(notFound),
		}, {
			Entity: params.Entity{
				Tag: names.NewPayloadTag("ce5bc2a7-65d8-4800-8199-a7c3356ab311").String(),
			},
			NotFound: false,
			Error:    nil,
		}},
	})
}
Пример #5
0
func (s *suite) TestLookUpOkay(c *gc.C) {
	id := "ce5bc2a7-65d8-4800-8199-a7c3356ab309"
	s.state.stateIDs = []string{id}

	a := UnitFacade{s.state}
	args := internal.LookUpArgs{
		Args: []internal.LookUpArg{{
			Name: "fooID",
			ID:   "bar",
		}},
	}
	res, err := a.LookUp(args)
	c.Assert(err, jc.ErrorIsNil)

	s.stub.CheckCalls(c, []testing.StubCall{{
		FuncName: "LookUp",
		Args:     []interface{}{"fooID", "bar"},
	}})

	c.Check(res, jc.DeepEquals, internal.PayloadResults{
		Results: []internal.PayloadResult{{
			Entity: params.Entity{
				Tag: names.NewPayloadTag(id).String(),
			},
			NotFound: false,
			Error:    nil,
		}},
	})
}
Пример #6
0
func (s *clientSuite) TestTrack(c *gc.C) {
	id := "ce5bc2a7-65d8-4800-8199-a7c3356ab309"
	numStubCalls := 0
	s.facade.FacadeCallFn = func(name string, args, response interface{}) error {
		numStubCalls++
		c.Check(name, gc.Equals, "Track")

		typedResponse, ok := response.(*internal.PayloadResults)
		c.Assert(ok, gc.Equals, true)
		typedResponse.Results = []internal.PayloadResult{{
			Entity: params.Entity{
				Tag: names.NewPayloadTag(id).String(),
			},
			Payload:  nil,
			NotFound: false,
			Error:    nil,
		}}
		return nil
	}

	pclient := client.NewUnitFacadeClient(s.facade)

	pl, err := api.API2Payload(s.payload)
	c.Assert(err, jc.ErrorIsNil)
	results, err := pclient.Track(pl.Payload)
	c.Assert(err, jc.ErrorIsNil)

	c.Check(numStubCalls, gc.Equals, 1)
	c.Check(results, jc.DeepEquals, []payload.Result{{
		ID:       id,
		Payload:  nil,
		NotFound: false,
		Error:    nil,
	}})
}
Пример #7
0
func ids2args(ids []string) params.Entities {
	var args params.Entities
	for _, id := range ids {
		tag := names.NewPayloadTag(id).String()
		args.Entities = append(args.Entities, params.Entity{
			Tag: tag,
		})
	}
	return args
}
Пример #8
0
// IDs2SetStatusArgs converts the provided payload IDs into arguments
// for the SetStatus API endpoint.
func IDs2SetStatusArgs(ids []string, status string) SetStatusArgs {
	var args SetStatusArgs
	for _, id := range ids {
		arg := SetStatusArg{
			Status: status,
		}
		arg.Tag = names.NewPayloadTag(id).String()
		args.Args = append(args.Args, arg)
	}
	return args
}
Пример #9
0
func (internalHelpersSuite) TestNewPayloadResultOkay(c *gc.C) {
	id := "ce5bc2a7-65d8-4800-8199-a7c3356ab309"
	result := private.NewPayloadResult(id, nil)

	c.Check(result, jc.DeepEquals, private.PayloadResult{
		Entity: params.Entity{
			Tag: names.NewPayloadTag(id).String(),
		},
		Payload:  nil,
		NotFound: false,
		Error:    nil,
	})
}
Пример #10
0
func (internalHelpersSuite) TestNewPayloadResultNotFound(c *gc.C) {
	id := "ce5bc2a7-65d8-4800-8199-a7c3356ab309"
	err := errors.NotFoundf("payload %q", id)
	result := private.NewPayloadResult(id, err)

	c.Check(result, jc.DeepEquals, private.PayloadResult{
		Entity: params.Entity{
			Tag: names.NewPayloadTag(id).String(),
		},
		Payload:  nil,
		NotFound: true,
		Error:    common.ServerError(err),
	})
}
Пример #11
0
func (internalHelpersSuite) TestResult2apiError(c *gc.C) {
	id := "ce5bc2a7-65d8-4800-8199-a7c3356ab309"
	err := errors.New("<failure>")
	result := private.Result2api(payload.Result{
		ID:       id,
		Payload:  nil,
		NotFound: false,
		Error:    err,
	})

	c.Check(result, jc.DeepEquals, private.PayloadResult{
		Entity: params.Entity{
			Tag: names.NewPayloadTag(id).String(),
		},
		Payload:  nil,
		NotFound: false,
		Error:    common.ServerError(err),
	})
}
Пример #12
0
// Result2api converts the payload.Result into a PayloadResult.
func Result2api(result payload.Result) PayloadResult {
	res := PayloadResult{
		NotFound: result.NotFound,
	}

	if result.ID != "" {
		res.Tag = names.NewPayloadTag(result.ID).String()
	}

	if result.Payload != nil {
		pl := api.Payload2api(*result.Payload)
		res.Payload = &pl
	}

	if result.Error != nil {
		res.Error = common.ServerError(result.Error)
	}

	return res
}
Пример #13
0
func (internalHelpersSuite) TestAPI2ResultError(c *gc.C) {
	id := "ce5bc2a7-65d8-4800-8199-a7c3356ab309"
	failure := errors.New("<failure>")
	result, err := private.API2Result(private.PayloadResult{
		Entity: params.Entity{
			Tag: names.NewPayloadTag(id).String(),
		},
		Payload:  nil,
		NotFound: false,
		Error:    common.ServerError(failure),
	})
	c.Assert(err, jc.ErrorIsNil)

	c.Check(result.Error.Error(), gc.Equals, failure.Error())
	c.Check(result, jc.DeepEquals, payload.Result{
		ID:       id,
		Payload:  nil,
		NotFound: false,
		Error:    result.Error, // The actual error is checked above.
	})
}
Пример #14
0
func (s *suite) TestTrack(c *gc.C) {
	id := "ce5bc2a7-65d8-4800-8199-a7c3356ab309"
	s.state.stateIDs = []string{id}

	a := UnitFacade{s.state}

	args := internal.TrackArgs{
		Payloads: []api.Payload{{
			Class:  "idfoo",
			Type:   "type",
			ID:     "bar",
			Status: payload.StateRunning,
		}},
	}

	res, err := a.Track(args)
	c.Assert(err, jc.ErrorIsNil)

	c.Check(res, jc.DeepEquals, internal.PayloadResults{
		Results: []internal.PayloadResult{{
			Entity: params.Entity{
				Tag: names.NewPayloadTag(id).String(),
			},
			Payload:  nil,
			NotFound: false,
			Error:    nil,
		}},
	})

	c.Check(s.state.payload, jc.DeepEquals, payload.Payload{
		PayloadClass: charm.PayloadClass{
			Name: "idfoo",
			Type: "type",
		},
		Status: payload.StateRunning,
		Labels: []string{},
		ID:     "bar",
	})
}
Пример #15
0
func (s *clientSuite) TestLookUpOkay(c *gc.C) {
	id := "ce5bc2a7-65d8-4800-8199-a7c3356ab309"
	response := &internal.PayloadResults{
		Results: []internal.PayloadResult{{
			Entity: params.Entity{
				Tag: names.NewPayloadTag(id).String(),
			},
			Payload:  nil,
			NotFound: false,
			Error:    nil,
		}},
	}
	s.facade.responses = append(s.facade.responses, response)

	pclient := client.NewUnitFacadeClient(s.facade)
	results, err := pclient.LookUp("idfoo/bar")
	c.Assert(err, jc.ErrorIsNil)

	c.Check(results, jc.DeepEquals, []payload.Result{{
		ID:       id,
		Payload:  nil,
		NotFound: false,
		Error:    nil,
	}})
	s.stub.CheckCalls(c, []testing.StubCall{{
		FuncName: "FacadeCall",
		Args: []interface{}{
			"LookUp",
			&internal.LookUpArgs{
				Args: []internal.LookUpArg{{
					Name: "idfoo",
					ID:   "bar",
				}},
			},
			response,
		},
	}})
}
Пример #16
0
func (internalHelpersSuite) TestAPI2ResultInfo(c *gc.C) {
	id := "ce5bc2a7-65d8-4800-8199-a7c3356ab309"
	result, err := private.API2Result(private.PayloadResult{
		Entity: params.Entity{
			Tag: names.NewPayloadTag(id).String(),
		},
		NotFound: false,
		Error:    nil,
		Payload: &api.Payload{
			Class:   "foobar",
			Type:    "type",
			ID:      "idfoo",
			Status:  payload.StateRunning,
			Unit:    "unit-a-service-0",
			Machine: "machine-1",
		},
	})
	c.Assert(err, jc.ErrorIsNil)

	c.Check(result, jc.DeepEquals, payload.Result{
		ID:       id,
		NotFound: false,
		Error:    nil,
		Payload: &payload.FullPayloadInfo{
			Payload: payload.Payload{
				PayloadClass: charm.PayloadClass{
					Name: "foobar",
					Type: "type",
				},
				ID:     "idfoo",
				Status: payload.StateRunning,
				Unit:   "a-service/0",
			},
			Machine: "1",
		},
	})
}
Пример #17
0
func (s *clientSuite) TestLookUpMulti(c *gc.C) {
	id1 := "ce5bc2a7-65d8-4800-8199-a7c3356ab309"
	id2 := "ce5bc2a7-65d8-4800-8199-a7c3356ab311"
	response := &internal.PayloadResults{
		Results: []internal.PayloadResult{{
			Entity: params.Entity{
				Tag: names.NewPayloadTag(id1).String(),
			},
			Payload:  nil,
			NotFound: false,
			Error:    nil,
		}, {
			Entity: params.Entity{
				Tag: "",
			},
			Payload:  nil,
			NotFound: true,
			Error:    common.ServerError(errors.NotFoundf("payload")),
		}, {
			Entity: params.Entity{
				Tag: names.NewPayloadTag(id2).String(),
			},
			Payload:  nil,
			NotFound: false,
			Error:    nil,
		}},
	}
	s.facade.responses = append(s.facade.responses, response)

	pclient := client.NewUnitFacadeClient(s.facade)
	results, err := pclient.LookUp("idfoo/bar", "idbaz/bam", "spam/eggs")
	c.Assert(err, jc.ErrorIsNil)

	c.Assert(results, gc.HasLen, 3)
	c.Assert(results[1].Error, gc.NotNil)
	results[1].Error = nil
	c.Check(results, jc.DeepEquals, []payload.Result{{
		ID:       id1,
		Payload:  nil,
		NotFound: false,
		Error:    nil,
	}, {
		ID:       "",
		Payload:  nil,
		NotFound: true,
		Error:    nil,
	}, {
		ID:       id2,
		Payload:  nil,
		NotFound: false,
		Error:    nil,
	}})
	s.stub.CheckCalls(c, []testing.StubCall{{
		FuncName: "FacadeCall",
		Args: []interface{}{
			"LookUp",
			&internal.LookUpArgs{
				Args: []internal.LookUpArg{{
					Name: "idfoo",
					ID:   "bar",
				}, {
					Name: "idbaz",
					ID:   "bam",
				}, {
					Name: "spam",
					ID:   "eggs",
				}},
			},
			response,
		},
	}})
}