Beispiel #1
0
func (s *contextSuite) TestPayloadsAPI(c *gc.C) {
	expected := s.apiClient.setNew("A/spam", "B/eggs", "C/ham")

	ctx := context.NewContext(s.apiClient, s.dataDir)
	context.AddPayload(ctx, "A/spam", s.apiClient.payloads["A/spam"])
	context.AddPayload(ctx, "B/eggs", s.apiClient.payloads["B/eggs"])
	context.AddPayload(ctx, "C/ham", s.apiClient.payloads["C/ham"])

	payloads, err := ctx.Payloads()
	c.Assert(err, jc.ErrorIsNil)

	checkPayloads(c, payloads, expected)
	s.Stub.CheckCallNames(c)
}
Beispiel #2
0
func (s *contextSuite) newContext(c *gc.C, payloads ...payload.Payload) *context.Context {
	ctx := context.NewContext(s.apiClient, s.dataDir)
	for _, pl := range payloads {
		c.Logf("adding payload: %s", pl.FullID())
		context.AddPayload(ctx, pl.FullID(), pl)
	}
	return ctx
}
Beispiel #3
0
func (s *contextSuite) TestGetOverride(c *gc.C) {
	payloads := s.apiClient.setNew("A/spam", "B/eggs")
	expected := payloads[0]

	unexpected := expected
	unexpected.ID = "C"

	ctx := s.newContext(c, payloads[1])
	context.AddPayload(ctx, "A/spam", unexpected)
	context.AddPayload(ctx, "A/spam", expected)

	pl, err := ctx.Get("A", "spam")
	c.Assert(err, jc.ErrorIsNil)

	c.Check(*pl, jc.DeepEquals, expected)
	s.Stub.CheckCallNames(c)
}
Beispiel #4
0
func (s *contextSuite) TestPayloadsOverrides(c *gc.C) {
	expected := s.apiClient.setNew("A/xyz123", "B/something-else")
	plB := s.newPayload("B", "myplugin", "xyz456", "running")
	plC := s.newPayload("C", "myplugin", "xyz789", "running")
	expected = append(expected[:1], plB, plC)

	ctx := context.NewContext(s.apiClient, s.dataDir)
	context.AddPayload(ctx, "A/xyz123", s.apiClient.payloads["A/xyz123"])
	context.AddPayload(ctx, "B/xyz456", plB)
	ctx.Track(plB)
	ctx.Track(plC)

	payloads, err := ctx.Payloads()
	c.Assert(err, jc.ErrorIsNil)

	checkPayloads(c, payloads, expected)
	s.Stub.CheckCallNames(c)
}
Beispiel #5
0
func (s *contextSuite) TestPayloadsAdditions(c *gc.C) {
	expected := s.apiClient.setNew("A/spam", "B/eggs")
	plC := s.newPayload("C", "myplugin", "xyz789", "running")
	plD := s.newPayload("D", "myplugin", "xyzabc", "running")
	expected = append(expected, plC, plD)

	ctx := s.newContext(c, expected[0])
	context.AddPayload(ctx, "B/eggs", s.apiClient.payloads["B/eggs"])
	ctx.Track(plC)
	ctx.Track(plD)

	payloads, err := ctx.Payloads()
	c.Assert(err, jc.ErrorIsNil)

	checkPayloads(c, payloads, expected)
	s.Stub.CheckCallNames(c)
}