本文整理匯總了Golang中testing.T.Spec方法的典型用法代碼示例。如果您正苦於以下問題:Golang T.Spec方法的具體用法?Golang T.Spec怎麽用?Golang T.Spec使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類testing.T
的用法示例。
在下文中一共展示了T.Spec方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestTemplateContext
func TestTemplateContext(t *testing.T) {
for _, testcase := range []struct {
Test string
Task *api.Task
Context Context
Expected *api.ContainerSpec
Err error
}{
{
Test: "Identity",
Task: modifyTask(func(t *api.Task) {
t.Spec = api.TaskSpec{
Runtime: &api.TaskSpec_Container{
Container: &api.ContainerSpec{
Env: []string{
"NOTOUCH=dont",
},
Mounts: []api.Mount{
{
Target: "foo",
Source: "bar",
},
},
},
},
}
}),
Expected: &api.ContainerSpec{
Env: []string{
"NOTOUCH=dont",
},
Mounts: []api.Mount{
{
Target: "foo",
Source: "bar",
},
},
},
},
{
Test: "Env",
Task: modifyTask(func(t *api.Task) {
t.Spec = api.TaskSpec{
Runtime: &api.TaskSpec_Container{
Container: &api.ContainerSpec{
Labels: map[string]string{
"ContainerLabel": "should-NOT-end-up-as-task",
},
Env: []string{
"MYENV=notemplate",
"{{.NotExpanded}}=foo",
"SERVICE_ID={{.Service.ID}}",
"SERVICE_NAME={{.Service.Name}}",
"TASK_ID={{.Task.ID}}",
"TASK_NAME={{.Task.Name}}",
"NODE_ID={{.Node.ID}}",
"SERVICE_LABELS={{range $k, $v := .Service.Labels}}{{$k}}={{$v}},{{end}}",
},
},
},
}
}),
Expected: &api.ContainerSpec{
Labels: map[string]string{
"ContainerLabel": "should-NOT-end-up-as-task",
},
Env: []string{
"MYENV=notemplate",
"{{.NotExpanded}}=foo",
"SERVICE_ID=serviceID",
"SERVICE_NAME=serviceName",
"TASK_ID=taskID",
"TASK_NAME=serviceName.10.taskID",
"NODE_ID=nodeID",
"SERVICE_LABELS=ServiceLabelOneKey=service-label-one-value,ServiceLabelTwoKey=service-label-two-value,com.example.ServiceLabelThreeKey=service-label-three-value,",
},
},
},
{
Test: "Mount",
Task: modifyTask(func(t *api.Task) {
t.Spec = api.TaskSpec{
Runtime: &api.TaskSpec_Container{
Container: &api.ContainerSpec{
Mounts: []api.Mount{
{
Source: "bar-{{.Node.ID}}-{{.Task.Name}}",
Target: "foo-{{.Service.ID}}-{{.Service.Name}}",
},
{
Source: "bar-{{.Node.ID}}-{{.Service.Name}}",
Target: "foo-{{.Task.Slot}}-{{.Task.ID}}",
},
},
},
},
}
}),
Expected: &api.ContainerSpec{
Mounts: []api.Mount{
//.........這裏部分代碼省略.........