Пример #1
0
func (s *ValueWorkerSuite) TestNewValueWorker_Success(c *gc.C) {
	w, err := util.NewValueWorker("cheese")
	c.Assert(err, jc.ErrorIsNil)

	err = worker.Stop(w)
	c.Check(err, jc.ErrorIsNil)
}
Пример #2
0
// newWorker creates a degenerate worker that provides access to an fslock.
func newWorker(a agent.Agent) (worker.Worker, error) {
	dataDir := a.CurrentConfig().DataDir()
	lock, err := createLock(dataDir)
	if err != nil {
		return nil, errors.Trace(err)
	}
	return util.NewValueWorker(lock)
}
Пример #3
0
// clockManifold expresses a Clock as a ValueWorker manifold.
func clockManifold(clock clock.Clock) dependency.Manifold {
	return dependency.Manifold{
		Start: func(_ dependency.Context) (worker.Worker, error) {
			return util.NewValueWorker(clock)
		},
		Output: util.ValueWorkerOutput,
	}
}
Пример #4
0
func (s *ValueWorkerSuite) TestValueWorkerOutput_BadOutputType(c *gc.C) {
	value := &testType{}
	w, err := util.NewValueWorker(value)
	c.Assert(err, jc.ErrorIsNil)

	var outVal string
	err = util.ValueWorkerOutput(w, &outVal)
	c.Check(err, gc.ErrorMatches, "cannot output into \\*string")
	c.Check(outVal, gc.Equals, "")
}
Пример #5
0
func (s *ValueWorkerSuite) TestValueWorkerOutput_BadOutputIndirection(c *gc.C) {
	value := &testType{}
	w, err := util.NewValueWorker(value)
	c.Assert(err, jc.ErrorIsNil)

	var outVal string
	err = util.ValueWorkerOutput(w, outVal)
	c.Check(err, gc.ErrorMatches, "out should be a pointer; is .*")
	c.Check(outVal, gc.Equals, "")
}
Пример #6
0
func (s *ValueWorkerSuite) TestValueWorkerOutput_Success(c *gc.C) {
	value := &testType{}
	w, err := util.NewValueWorker(value)
	c.Assert(err, jc.ErrorIsNil)

	var outVal testInterface
	err = util.ValueWorkerOutput(w, &outVal)
	c.Check(err, jc.ErrorIsNil)
	c.Check(outVal, gc.DeepEquals, value)
}
Пример #7
0
func (s *ValueWorkerSuite) TestNewValueWorker_NilValue(c *gc.C) {
	w, err := util.NewValueWorker(nil)
	c.Check(err, gc.ErrorMatches, "NewValueWorker expects a value")
	c.Check(w, gc.IsNil)
}