我了解 maps in go,但这段代码让我感到困惑:
testCases := map[string]struct {
pod *api.Pod
required []corev1.ResourceName
err string
}{
"init container resource missing": {
pod: &api.Pod{
Spec: api.PodSpec{
InitContainers: []api.Container{{
Resources: api.ResourceRequirements{
Requests: api.ResourceList{api.ResourceCPU: resource.MustParse("1m")},
Limits: api.ResourceList{api.ResourceCPU: resource.MustParse("2m")},
},
}},
},
},
required: []corev1.ResourceName{corev1.ResourceMemory},
err: `must specify memory`,
},
"container resource missing": {
pod: &api.Pod{
Spec: api.PodSpec{
Containers: []api.Container{{
Resources: api.ResourceRequirements{
Requests: api.ResourceList{api.ResourceCPU: resource.MustParse("1m")},
Limits: api.ResourceList{api.ResourceCPU: resource.MustParse("2m")},
},
}},
},
},
required: []corev1.ResourceName{corev1.ResourceMemory},
err: `must specify memory`,
},
}
我明白这一点:
testCases := map[string]struct
但接下来的内容对我来说毫无意义。代码如何自己定义一个 api.Pod、corev1.ResourceName 等?那不是struct定义的字符串吗?
侃侃尔雅
慕神8447489
相关分类