Beispiel #1
0
func (s *FlagSuite) TestNonEmptyInputs(c *gc.C) {
	base := dependency.Manifold{
		Inputs: []string{"foo", "bar"},
	}
	wrapped := dependency.WithFlag(base, "blib")
	expect := []string{"foo", "bar", "blib"}
	c.Check(wrapped.Inputs, jc.DeepEquals, expect)
}
Beispiel #2
0
func (s *FlagSuite) TestStartFalseFlag(c *gc.C) {
	wrapped := dependency.WithFlag(dependency.Manifold{}, "foo")
	getResource := dt.StubGetResource(dt.StubResources{
		"foo": dt.StubResource{Output: stubFlag(false)},
	})
	worker, err := wrapped.Start(getResource)
	c.Check(worker, gc.IsNil)
	c.Check(errors.Cause(err), gc.Equals, dependency.ErrMissing)
}
Beispiel #3
0
func (s *FlagSuite) TestStartNotFlag(c *gc.C) {
	wrapped := dependency.WithFlag(dependency.Manifold{}, "foo")
	getResource := dt.StubGetResource(dt.StubResources{
		"foo": dt.StubResource{Output: true},
	})
	worker, err := wrapped.Start(getResource)
	c.Check(worker, gc.IsNil)
	c.Check(err, gc.ErrorMatches, `cannot set true into \*dependency.Flag`)
}
Beispiel #4
0
func (s *FlagSuite) TestNonEmptyOutput(c *gc.C) {
	output := func(_ worker.Worker, _ interface{}) error {
		panic("splat")
	}
	base := dependency.Manifold{
		Output: output,
	}
	wrapped := dependency.WithFlag(base, "blah")
	tryOutput := func() {
		wrapped.Output(nil, nil)
	}
	c.Check(tryOutput, gc.PanicMatches, "splat")
}
Beispiel #5
0
func (s *FlagSuite) TestStartTrueFlag(c *gc.C) {
	expectWorker := &stubWorker{}
	base := dependency.Manifold{
		Start: func(_ dependency.GetResourceFunc) (worker.Worker, error) {
			return expectWorker, nil
		},
	}
	wrapped := dependency.WithFlag(base, "foo")
	getResource := dt.StubGetResource(dt.StubResources{
		"foo": dt.StubResource{Output: stubFlag(true)},
	})
	worker, err := wrapped.Start(getResource)
	c.Check(worker, gc.Equals, expectWorker)
	c.Check(err, jc.ErrorIsNil)
}
Beispiel #6
0
// ifNotDead wraps a manifold such that it only runs if the responsibility
// flag is set and the model is Alive or Dying.
func ifNotDead(manifold dependency.Manifold) dependency.Manifold {
	return ifResponsible(dependency.WithFlag(manifold, notDeadFlagName))
}
Beispiel #7
0
// ifResponsible wraps a manifold such that it only runs if the
// responsibility flag is set.
func ifResponsible(manifold dependency.Manifold) dependency.Manifold {
	return dependency.WithFlag(manifold, isResponsibleFlagName)
}
Beispiel #8
0
func (s *FlagSuite) TestEmptyOutput(c *gc.C) {
	wrapped := dependency.WithFlag(dependency.Manifold{}, "blob")
	c.Check(wrapped.Output, gc.IsNil)
}
Beispiel #9
0
func (s *FlagSuite) TestEmptyInputs(c *gc.C) {
	wrapped := dependency.WithFlag(dependency.Manifold{}, "blob")
	c.Check(wrapped.Inputs, jc.DeepEquals, []string{"blob"})
}