// RunDumb starts a DumbWorkers inside a fresh Context and supplies it // to a test func. func (fix Fixture) RunDumb(c *gc.C, test func(Context, *workers.DumbWorkers)) { fix.Run(c, func(ctx Context) { dw, err := workers.NewDumbWorkers(workers.DumbConfig{ Factory: ctx.Factory(), Logger: loggo.GetLogger("test"), }) c.Assert(err, jc.ErrorIsNil) defer workertest.DirtyKill(c, dw) test(ctx, dw) }) }
// FailDumb verifies that a DumbWorkers cannot start successfully, and // checks that the returned error matches. func (fix Fixture) FailDumb(c *gc.C, match string) { fix.Run(c, func(ctx Context) { dw, err := workers.NewDumbWorkers(workers.DumbConfig{ Factory: ctx.Factory(), Logger: loggo.GetLogger("test"), }) if !c.Check(dw, gc.IsNil) { workertest.DirtyKill(c, dw) } c.Check(err, gc.ErrorMatches, match) }) }
func (*DumbWorkersSuite) TestValidateMissingFactory(c *gc.C) { config := workers.DumbConfig{ Logger: loggo.GetLogger("test"), } check := func(err error) { c.Check(err, gc.ErrorMatches, "nil Factory not valid") c.Check(err, jc.Satisfies, errors.IsNotValid) } check(config.Validate()) w, err := workers.NewDumbWorkers(config) if !c.Check(w, gc.IsNil) { workertest.CleanKill(c, w) } check(err) }
func (*DumbWorkersSuite) TestValidateUninitializedLogger(c *gc.C) { config := workers.DumbConfig{ Factory: struct{ workers.Factory }{}, } check := func(err error) { c.Check(err, gc.ErrorMatches, "uninitialized Logger not valid") c.Check(err, jc.Satisfies, errors.IsNotValid) } check(config.Validate()) w, err := workers.NewDumbWorkers(config) if !c.Check(w, gc.IsNil) { workertest.CleanKill(c, w) } check(err) }