コード例 #1
0
ファイル: namespace.go プロジェクト: dmaze/goordinate
// TestSpecCreateDestroy performs basic work spec lifetime tests.
func (s *Suite) TestSpecCreateDestroy(c *check.C) {
	var (
		data  map[string]interface{}
		dict  map[string]interface{}
		spec  coordinate.WorkSpec
		name  string
		names []string
		err   error
	)
	name = "spec"

	spec, err = s.Namespace.WorkSpec(name)
	c.Check(err, check.DeepEquals,
		coordinate.ErrNoSuchWorkSpec{Name: name})

	names, err = s.Namespace.WorkSpecNames()
	c.Assert(err, check.IsNil)
	c.Check(names, check.HasLen, 0)

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

	spec, err = s.Namespace.WorkSpec(name)
	c.Assert(err, check.IsNil)
	c.Check(spec, check.NotNil)
	c.Check(spec.Name(), check.Equals, name)

	data, err = spec.Data()
	c.Assert(err, check.IsNil)
	c.Check(data, check.DeepEquals, dict)

	names, err = s.Namespace.WorkSpecNames()
	c.Assert(err, check.IsNil)
	c.Check(names, check.DeepEquals, []string{name})

	err = s.Namespace.DestroyWorkSpec(name)
	c.Check(err, check.IsNil)

	spec, err = s.Namespace.WorkSpec(name)
	c.Check(err, check.DeepEquals,
		coordinate.ErrNoSuchWorkSpec{Name: name})

	names, err = s.Namespace.WorkSpecNames()
	c.Assert(err, check.IsNil)
	c.Check(names, check.HasLen, 0)

	err = s.Namespace.DestroyWorkSpec(name)
	c.Check(err, check.DeepEquals,
		coordinate.ErrNoSuchWorkSpec{Name: name})
}
コード例 #2
0
ファイル: work_spec.go プロジェクト: dmaze/goordinate
// 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")
}
コード例 #3
0
ファイル: specs.go プロジェクト: dmaze/goordinate
func getWorkSpecData(spec coordinate.WorkSpec) (map[string]interface{}, error) {
	data, err := spec.Data()
	if err != nil {
		return nil, err
	}
	byteify := func(key string) {
		value, present := data[key]
		if !present {
			return
		}
		string, ok := value.(string)
		if !ok {
			return
		}
		data[key] = []byte(string)
	}
	byteify("module")
	byteify("run_function")
	return data, nil
}