Пример #1
0
// TestTrivialWorkUnitFlow tests work unit creation, deletion, and existence.
func (s *Suite) TestTrivialWorkUnitFlow(c *check.C) {
	var (
		count int
		err   error
		spec  coordinate.WorkSpec
		unit  coordinate.WorkUnit
		units map[string]coordinate.WorkUnit
	)

	spec, err = s.Namespace.SetWorkSpec(map[string]interface{}{
		"name":   "spec",
		"min_gb": 1,
	})
	c.Assert(err, check.IsNil)

	unit, err = spec.AddWorkUnit("unit", map[string]interface{}{}, 0)
	c.Assert(err, check.IsNil)
	c.Check(unit.Name(), check.Equals, "unit")
	c.Check(unit.WorkSpec().Name(), check.Equals, "spec")

	unit, err = spec.WorkUnit("unit")
	c.Assert(err, check.IsNil)
	c.Check(unit.Name(), check.Equals, "unit")
	c.Check(unit.WorkSpec().Name(), check.Equals, "spec")

	units, err = spec.WorkUnits(coordinate.WorkUnitQuery{})
	c.Assert(err, check.IsNil)
	c.Check(units, check.HasLen, 1)
	c.Check(units["unit"], check.NotNil)
	c.Check(units["unit"].Name(), check.Equals, "unit")
	c.Check(units["unit"].WorkSpec().Name(), check.Equals, "spec")

	count, err = spec.DeleteWorkUnits(coordinate.WorkUnitQuery{})
	c.Assert(err, check.IsNil)
	c.Check(count, check.Equals, 1)

	unit, err = spec.WorkUnit("unit")
	c.Assert(err, check.IsNil)
	c.Check(unit, check.IsNil)

	units, err = spec.WorkUnits(coordinate.WorkUnitQuery{})
	c.Assert(err, check.IsNil)
	c.Check(units, check.HasLen, 0)
}