Exemple #1
0
func (s *filterSuite) TestFilterNoPayloads(c *gc.C) {
	predicate := func(payload.FullPayloadInfo) bool {
		return true
	}
	matched := payload.Filter(nil, predicate)

	c.Check(matched, gc.HasLen, 0)
}
Exemple #2
0
func (s *filterSuite) TestFilterMatchNone(c *gc.C) {
	payloads := []payload.FullPayloadInfo{
		s.newPayload("spam"),
	}
	predicate := func(payload.FullPayloadInfo) bool {
		return false
	}
	matched := payload.Filter(payloads, predicate)

	c.Check(matched, gc.HasLen, 0)
}
Exemple #3
0
func (s *filterSuite) TestFilterOkay(c *gc.C) {
	payloads := []payload.FullPayloadInfo{
		s.newPayload("spam"),
	}
	predicate := func(payload.FullPayloadInfo) bool {
		return true
	}
	matched := payload.Filter(payloads, predicate)

	c.Check(matched, jc.DeepEquals, payloads)
}
Exemple #4
0
func (s *filterSuite) TestFilterMatchPartial(c *gc.C) {
	payloads := []payload.FullPayloadInfo{
		s.newPayload("spam"),
		s.newPayload("eggs"),
	}
	predicate := func(p payload.FullPayloadInfo) bool {
		return p.Name == "spam"
	}
	matched := payload.Filter(payloads, predicate)

	c.Check(matched, jc.DeepEquals, payloads[:1])
}
Exemple #5
0
func (s *filterSuite) TestFilterMultiMatch(c *gc.C) {
	payloads := []payload.FullPayloadInfo{
		s.newPayload("spam"),
		s.newPayload("eggs"),
	}
	predA := func(p payload.FullPayloadInfo) bool {
		return p.Name == "spam"
	}
	predB := func(p payload.FullPayloadInfo) bool {
		return p.Name == "eggs"
	}
	matched := payload.Filter(payloads, predA, predB)

	c.Check(matched, jc.DeepEquals, payloads)
}
Exemple #6
0
// List builds the list of payloads being tracked for
// the given unit and IDs. If no IDs are provided then all tracked
// payloads for the unit are returned.
func (a PublicAPI) List(args api.EnvListArgs) (api.EnvListResults, error) {
	var r api.EnvListResults

	payloads, err := a.State.ListAll()
	if err != nil {
		return r, errors.Trace(err)
	}

	filters, err := payload.BuildPredicatesFor(args.Patterns)
	if err != nil {
		return r, errors.Trace(err)
	}
	payloads = payload.Filter(payloads, filters...)

	for _, payload := range payloads {
		apiInfo := api.Payload2api(payload)
		r.Results = append(r.Results, apiInfo)
	}
	return r, nil
}