当前位置: 首页>>代码示例>>Golang>>正文


Golang WorkSpec.Data方法代码示例

本文整理汇总了Golang中github.com/dmaze/goordinate/coordinate.WorkSpec.Data方法的典型用法代码示例。如果您正苦于以下问题:Golang WorkSpec.Data方法的具体用法?Golang WorkSpec.Data怎么用?Golang WorkSpec.Data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/dmaze/goordinate/coordinate.WorkSpec的用法示例。


在下文中一共展示了WorkSpec.Data方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestSpecCreateDestroy

// 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})
}
开发者ID:dmaze,项目名称:goordinate,代码行数:57,代码来源:namespace.go

示例2: TestChangeSpecData

// 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")
}
开发者ID:dmaze,项目名称:goordinate,代码行数:45,代码来源:work_spec.go

示例3: getWorkSpecData

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
}
开发者ID:dmaze,项目名称:goordinate,代码行数:20,代码来源:specs.go


注:本文中的github.com/dmaze/goordinate/coordinate.WorkSpec.Data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。