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


Golang Unit.CurrentState方法代码示例

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


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

示例1: mapJobToSchema

func mapJobToSchema(j *job.Job) (*schema.Unit, error) {
	su := schema.Unit{
		Name:            j.Name,
		FileHash:        j.Unit.Hash().String(),
		FileContents:    encodeUnitContents(&j.Unit),
		TargetMachineID: j.TargetMachineID,
		DesiredState:    string(j.TargetState),
	}

	if j.State != nil {
		su.CurrentState = string(*(j.State))
	}

	if j.UnitState != nil {
		su.Systemd = &schema.SystemdState{
			LoadState:   j.UnitState.LoadState,
			ActiveState: j.UnitState.ActiveState,
			SubState:    j.UnitState.SubState,
		}
		if j.UnitState.MachineID != "" {
			su.Systemd.MachineID = j.UnitState.MachineID
		}
	}

	return &su, nil
}
开发者ID:JuanCarlosM,项目名称:fleet,代码行数:26,代码来源:units.go

示例2: TestListUnitFilesFieldsToStrings

func TestListUnitFilesFieldsToStrings(t *testing.T) {
	u := schema.Unit{
		Name:    "foo.service",
		Options: []*schema.UnitOption{},
	}

	for k, v := range map[string]string{
		"hash":     "da39a3e",
		"desc":     "-",
		"dstate":   "-",
		"tmachine": "-",
		"state":    "-",
	} {
		f := listUnitFilesFields[k](u, false)
		assertEqual(t, k, v, f)
	}

	f := listUnitFilesFields["unit"](u, false)
	assertEqual(t, "unit", u.Name, f)

	u = schema.Unit{
		Name: "foo.service",
		Options: []*schema.UnitOption{
			&schema.UnitOption{Section: "Unit", Name: "Description", Value: "some description"},
		},
	}

	d := listUnitFilesFields["desc"](u, false)
	assertEqual(t, "desc", "some description", d)

	for _, state := range []job.JobState{job.JobStateLoaded, job.JobStateInactive, job.JobStateLaunched} {
		u.CurrentState = string(state)
		f := listUnitFilesFields["state"](u, false)
		assertEqual(t, "state", string(state), f)
	}

	// machineStates must be initialized since cAPI is not set
	machineStates = map[string]*machine.MachineState{}

	u.MachineID = "some-id"
	ms := listUnitFilesFields["tmachine"](u, true)
	assertEqual(t, "machine", "some-id", ms)

	u.MachineID = "other-id"
	machineStates = map[string]*machine.MachineState{
		"other-id": &machine.MachineState{
			ID:       "other-id",
			PublicIP: "1.2.3.4",
		},
	}
	ms = listUnitFilesFields["tmachine"](u, true)
	assertEqual(t, "machine", "other-id/1.2.3.4", ms)

	uh := "a0f275d46bc6ee0eca06be7c339913c07d99c0c7"
	fuh := listUnitFilesFields["hash"](u, true)
	suh := listUnitFilesFields["hash"](u, false)
	assertEqual(t, "hash", uh, fuh)
	assertEqual(t, "hash", uh[:7], suh)
}
开发者ID:ericcapricorn,项目名称:fleet,代码行数:59,代码来源:list_unit_files_test.go


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