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


Golang WorkSpec.Name方法代码示例

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


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

示例1: TestSpecCreateDestroy

// TestSpecCreateDestroy performs basic work spec lifetime tests.
func TestSpecCreateDestroy(t *testing.T) {
	var (
		dict  map[string]interface{}
		spec  coordinate.WorkSpec
		name  string
		names []string
		err   error
	)

	sts := SimpleTestSetup{
		NamespaceName: "TestSpecCreateDestroy",
	}
	sts.SetUp(t)
	defer sts.TearDown(t)
	name = "spec"

	spec, err = sts.Namespace.WorkSpec(name)
	assert.Equal(t, coordinate.ErrNoSuchWorkSpec{Name: name}, err)

	names, err = sts.Namespace.WorkSpecNames()
	if assert.NoError(t, err) {
		assert.Len(t, names, 0)
	}

	dict = map[string]interface{}{
		"name":   name,
		"min_gb": 0.1,
	}
	spec, err = sts.Namespace.SetWorkSpec(dict)
	if assert.NoError(t, err) && assert.NotNil(t, spec) {
		assert.Equal(t, name, spec.Name())
	}

	spec, err = sts.Namespace.WorkSpec(name)
	if assert.NoError(t, err) && assert.NotNil(t, spec) {
		assert.Equal(t, name, spec.Name())
	}

	DataMatches(t, spec, dict)

	names, err = sts.Namespace.WorkSpecNames()
	if assert.NoError(t, err) {
		assert.Equal(t, []string{name}, names)
	}

	err = sts.Namespace.DestroyWorkSpec(name)
	assert.NoError(t, err)

	spec, err = sts.Namespace.WorkSpec(name)
	assert.Equal(t, coordinate.ErrNoSuchWorkSpec{Name: name}, err)

	names, err = sts.Namespace.WorkSpecNames()
	if assert.NoError(t, err) {
		assert.Len(t, names, 0)
	}

	err = sts.Namespace.DestroyWorkSpec(name)
	assert.Equal(t, coordinate.ErrNoSuchWorkSpec{Name: name}, err)
}
开发者ID:diffeo,项目名称:go-coordinate,代码行数:60,代码来源:namespace.go

示例2: fillWorkUnitShort

func (api *restAPI) fillWorkUnitShort(namespace coordinate.Namespace, spec coordinate.WorkSpec, name string, short *restdata.WorkUnitShort) error {
	short.Name = name
	return buildURLs(api.Router,
		"namespace", namespace.Name(),
		"spec", spec.Name(),
		"unit", name,
	).URL(&short.URL, "workUnit").Error
}
开发者ID:diffeo,项目名称:go-coordinate,代码行数:8,代码来源:work_unit.go

示例3: fillWorkUnit

func (api *restAPI) fillWorkUnit(namespace coordinate.Namespace, spec coordinate.WorkSpec, unit coordinate.WorkUnit, repr *restdata.WorkUnit) error {
	err := api.fillWorkUnitShort(namespace, spec, unit.Name(), &repr.WorkUnitShort)
	if err == nil {
		repr.Data, err = unit.Data()
	}
	if err == nil {
		var meta coordinate.WorkUnitMeta
		meta, err = unit.Meta()
		repr.Meta = &meta
	}
	if err == nil {
		repr.Status, err = unit.Status()
	}
	if err == nil {
		err = buildURLs(api.Router,
			"namespace", namespace.Name(),
			"spec", spec.Name(),
			"unit", unit.Name(),
		).
			URL(&repr.WorkSpecURL, "workSpec").
			URL(&repr.AttemptsURL, "workUnitAttempts").
			Error
	}
	if err == nil {
		var attempt coordinate.Attempt
		attempt, err = unit.ActiveAttempt()
		if err == nil && attempt != nil {
			// This is cheating, a little, but it's probably
			// the easiest way to reuse this code
			var short restdata.AttemptShort
			err = api.fillAttemptShort(namespace, attempt, &short)
			if err == nil {
				repr.ActiveAttemptURL = short.URL
			}
		}
	}
	return err
}
开发者ID:diffeo,项目名称:go-coordinate,代码行数:38,代码来源:work_unit.go

示例4: TestTwoWorkSpecsBasic

// TestTwoWorkSpecsBasic ensures that two work specs can be created
// and have independent lifetimes.
func TestTwoWorkSpecsBasic(t *testing.T) {
	var (
		err          error
		dict1, dict2 map[string]interface{}
		name1, name2 string
		names        []string
		spec         coordinate.WorkSpec
	)

	namespace, err := Coordinate.Namespace("TestTwoWorkSpecsBasic")
	if !assert.NoError(t, err) {
		return
	}
	defer namespace.Destroy()

	name1 = "spec1"
	name2 = "spec2"

	dict1 = map[string]interface{}{"name": name1, "min_gb": 1}
	dict2 = map[string]interface{}{"name": name2, "min_gb": 2}

	names, err = namespace.WorkSpecNames()
	if assert.NoError(t, err) {
		assert.Len(t, names, 0)
	}

	spec, err = namespace.SetWorkSpec(dict1)
	assert.NoError(t, err)

	names, err = namespace.WorkSpecNames()
	if assert.NoError(t, err) {
		assert.Equal(t, []string{name1}, names)
	}

	spec, err = namespace.SetWorkSpec(dict2)
	assert.NoError(t, err)

	names, err = namespace.WorkSpecNames()
	if assert.NoError(t, err) {
		assert.Len(t, names, 2)
		assert.Contains(t, names, name1)
		assert.Contains(t, names, name2)
	}

	spec, err = namespace.WorkSpec(name1)
	if assert.NoError(t, err) && assert.NotNil(t, spec) {
		assert.Equal(t, name1, spec.Name())
	}

	spec, err = namespace.WorkSpec(name2)
	if assert.NoError(t, err) && assert.NotNil(t, spec) {
		assert.Equal(t, name2, spec.Name())
	}

	err = namespace.DestroyWorkSpec(name1)
	assert.NoError(t, err)

	names, err = namespace.WorkSpecNames()
	if assert.NoError(t, err) {
		assert.Len(t, names, 1)
		assert.Contains(t, names, name2)
	}

	spec, err = namespace.WorkSpec(name1)
	assert.Equal(t, coordinate.ErrNoSuchWorkSpec{Name: name1}, err)

	spec, err = namespace.WorkSpec(name2)
	if assert.NoError(t, err) && assert.NotNil(t, spec) {
		assert.Equal(t, name2, spec.Name())
	}

	err = namespace.DestroyWorkSpec(name2)
	assert.NoError(t, err)

	names, err = namespace.WorkSpecNames()
	if assert.NoError(t, err) {
		assert.Len(t, names, 0)
	}

	spec, err = namespace.WorkSpec(name1)
	assert.Equal(t, coordinate.ErrNoSuchWorkSpec{Name: name1}, err)

	spec, err = namespace.WorkSpec(name2)
	assert.Equal(t, coordinate.ErrNoSuchWorkSpec{Name: name2}, err)
}
开发者ID:diffeo,项目名称:go-coordinate,代码行数:87,代码来源:namespace.go


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