示例#1
0
// TestSetDataSetsMeta tests that...yeah
func (s *Suite) TestSetDataSetsMeta(c *check.C) {
	var (
		err  error
		spec coordinate.WorkSpec
		meta coordinate.WorkSpecMeta
	)
	spec, err = s.Namespace.SetWorkSpec(map[string]interface{}{
		"name":   "spec",
		"min_gb": 1,
	})
	c.Assert(err, check.IsNil)

	meta, err = spec.Meta(false)
	c.Assert(err, check.IsNil)
	c.Check(meta.Priority, check.Equals, 0)
	c.Check(meta.Weight, check.Equals, 20)
	c.Check(meta.Paused, check.Equals, false)
	c.Check(meta.Continuous, check.Equals, false)
	c.Check(meta.CanBeContinuous, check.Equals, false)
	c.Check(meta.Interval, check.Equals, time.Duration(0))
	c.Check(meta.NextContinuous, check.Equals, time.Time{})
	c.Check(meta.MaxRunning, check.Equals, 0)
	c.Check(meta.MaxAttemptsReturned, check.Equals, 0)
	c.Check(meta.NextWorkSpecName, check.Equals, "")
	c.Check(meta.AvailableCount, check.Equals, 0)
	c.Check(meta.PendingCount, check.Equals, 0)

	err = spec.SetData(map[string]interface{}{
		"name":        "spec",
		"min_gb":      1,
		"priority":    10,
		"weight":      100,
		"disabled":    true,
		"continuous":  true,
		"interval":    60,
		"max_running": 10,
		"max_getwork": 1,
		"then":        "spec2",
	})
	c.Assert(err, check.IsNil)

	meta, err = spec.Meta(false)
	c.Assert(err, check.IsNil)
	c.Check(meta.Priority, check.Equals, 10)
	c.Check(meta.Weight, check.Equals, 100)
	c.Check(meta.Paused, check.Equals, true)
	c.Check(meta.Continuous, check.Equals, true)
	c.Check(meta.CanBeContinuous, check.Equals, true)
	c.Check(meta.Interval, check.Equals, time.Duration(60)*time.Second)
	c.Check(meta.NextContinuous, check.Equals, time.Time{})
	c.Check(meta.MaxRunning, check.Equals, 10)
	c.Check(meta.MaxAttemptsReturned, check.Equals, 1)
	c.Check(meta.NextWorkSpecName, check.Equals, "spec2")
	c.Check(meta.AvailableCount, check.Equals, 0)
	c.Check(meta.PendingCount, check.Equals, 0)
}
示例#2
0
// TestChangeSpecData tests WorkSpec.SetData().
func (s *Suite) TestChangeSpecData(c *check.C) {
	var (
		err  error
		data map[string]interface{}
		spec coordinate.WorkSpec
	)

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

	err = spec.SetData(map[string]interface{}{
		"name":   "spec",
		"min_gb": 2,
		"foo":    "bar",
	})
	c.Assert(err, check.IsNil)

	data, err = spec.Data()
	c.Assert(err, check.IsNil)
	c.Check(data["name"], check.Equals, "spec")
	c.Check(data["min_gb"], Like, 2)
	c.Check(data["foo"], check.Equals, "bar")

	err = spec.SetData(map[string]interface{}{})
	c.Assert(err, check.NotNil)
	c.Check(err, check.Equals, coordinate.ErrNoWorkSpecName)

	err = spec.SetData(map[string]interface{}{
		"name":   "name",
		"min_gb": 3,
	})
	c.Assert(err, check.NotNil)
	c.Check(err, check.Equals, coordinate.ErrChangedName)

	data, err = spec.Data()
	c.Assert(err, check.IsNil)
	c.Check(data["name"], check.Equals, "spec")
	c.Check(data["min_gb"], Like, 2)
	c.Check(data["foo"], check.Equals, "bar")
}