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) }
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) }
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`) }
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") }
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) }
// 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)) }
// 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) }
func (s *FlagSuite) TestEmptyOutput(c *gc.C) { wrapped := dependency.WithFlag(dependency.Manifold{}, "blob") c.Check(wrapped.Output, gc.IsNil) }
func (s *FlagSuite) TestEmptyInputs(c *gc.C) { wrapped := dependency.WithFlag(dependency.Manifold{}, "blob") c.Check(wrapped.Inputs, jc.DeepEquals, []string{"blob"}) }