Beispiel #1
0
// 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)
	})
}
Beispiel #2
0
// 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)
	})
}
Beispiel #3
0
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)
}
Beispiel #4
0
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)
}