Beispiel #1
0
func (s *contextSuite) TestNewContextEmpty(c *gc.C) {
	ctx := context.NewContext(s.apiClient, s.dataDir)
	payloads, err := ctx.Payloads()
	c.Assert(err, jc.ErrorIsNil)

	c.Check(payloads, gc.HasLen, 0)
}
Beispiel #2
0
func (s *contextSuite) TestFlushEmpty(c *gc.C) {
	ctx := context.NewContext(s.apiClient, s.dataDir)
	err := ctx.Flush()
	c.Assert(err, jc.ErrorIsNil)

	s.Stub.CheckCallNames(c)
}
Beispiel #3
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 #4
0
func (s *contextSuite) SetUpTest(c *gc.C) {
	s.baseSuite.SetUpTest(c)

	s.apiClient = newStubAPIClient(s.Stub)
	s.dataDir = "some-data-dir"
	s.compCtx = context.NewContext(s.apiClient, s.dataDir)

	context.AddPayloads(s.compCtx, s.payload)
}
Beispiel #5
0
func (s *contextSuite) TestContextComponentOkay(c *gc.C) {
	hctx, info := s.NewHookContext()
	expected := context.NewContext(s.apiClient, s.dataDir)
	info.SetComponent(payload.ComponentName, expected)

	compCtx, err := context.ContextComponent(hctx)
	c.Assert(err, jc.ErrorIsNil)

	c.Check(compCtx, gc.Equals, expected)
	s.Stub.CheckCallNames(c, "Component")
	s.Stub.CheckCall(c, 0, "Component", payload.ComponentName)
}
Beispiel #6
0
func (s *contextSuite) TestUntrackNoMatch(c *gc.C) {
	pl := s.newPayload("A", "myplugin", "spam", "running")
	ctx := context.NewContext(s.apiClient, s.dataDir)
	err := ctx.Track(pl)
	c.Assert(err, jc.ErrorIsNil)
	before, err := ctx.Payloads()
	c.Assert(err, jc.ErrorIsNil)
	c.Check(before, jc.DeepEquals, []payload.Payload{pl})
	ctx.Untrack("uh-oh", "not gonna match")
	after, err := ctx.Payloads()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(after, gc.DeepEquals, before)
}
Beispiel #7
0
func (s *contextSuite) TestSetOkay(c *gc.C) {
	pl := s.newPayload("A", "myplugin", "spam", "running")
	ctx := context.NewContext(s.apiClient, s.dataDir)
	before, err := ctx.Payloads()
	c.Assert(err, jc.ErrorIsNil)
	err = ctx.Track(pl)
	c.Assert(err, jc.ErrorIsNil)
	after, err := ctx.Payloads()
	c.Assert(err, jc.ErrorIsNil)

	c.Check(before, gc.HasLen, 0)
	c.Check(after, jc.DeepEquals, []payload.Payload{pl})
}
Beispiel #8
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 #9
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 #10
0
func (s *contextSuite) TestGetNotFound(c *gc.C) {
	ctx := context.NewContext(s.apiClient, s.dataDir)
	_, err := ctx.Get("A", "spam")

	c.Check(err, jc.Satisfies, errors.IsNotFound)
}