當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。