Repository: kubernetes/kubernetes
File: pkg/kubelet/cm/qos_container_manager_linux_test.go (Go)

Code before:
func guaranteedAndBurstableTestPods() []*v1.Pod {
	pods := []*v1.Pod{}
	pods = append(pods, guaranteedTestPods()...)
	pods = append(pods, burstableTestPods()...)
	return pods
}
func besteffortAndBurstableTestPods() []*v1.Pod {
	pods := []*v1.Pod{}
	pods = append(pods, bestEffortTestPods()...)
	pods = append(pods, burstableTestPods()...)
	return pods
}

// TestQOSCPUConfigUpdate verifies that UpdateCgroups() computes and
// updates the correct CPU shares for each QoS class based on the
// currently active pods.
func TestQOSCPUConfigUpdate(t *testing.T) {

	tests := []struct {
		name              string
		testPods          ActivePodsFunc
		expectedCPUShares uint64
	}{
		{
			name:              "guaranteed-pods-only",
			testPods:          guaranteedTestPods,
			expectedCPUShares: expectedCPUShares(guaranteedTestPods),
		},
		{
			name:              "burstable-pods-only",
			testPods:          burstableTestPods,
			expectedCPUShares: expectedCPUShares(burstableTestPods),
		},
		{
			name:              "besteffort-pods-only",
			testPods:          bestEffortTestPods,
			expectedCPUShares: expectedCPUShares(bestEffortTestPods),
		},
		{
			name:              "guaranteed-and-burstable-pods",
			testPods:          guaranteedAndBurstableTestPods,
			expectedCPUShares: expectedCPUShares(guaranteedAndBurstableTestPods),
		},
		{
			name:              "besteffort-and-burstable-pods",
			testPods:          besteffortAndBurstableTestPods,
			expectedCPUShares: expectedCPUShares(besteffortAndBurstableTestPods),
		},
	}

	for _, testCase := range tests {

Review comment (suggestion):
anonyomous inline functions which return the expected pod slice is probably more intent-revealing and I'd prefer this approach in test code

Code after:
						},
					},
				}
			},
			expectedBurstableCPUShares: MinShares,
		},
		{
			name: "guaranteed-and-burstable-pods",
			testPods: func() []*v1.Pod {
				return []*v1.Pod{
					{
						ObjectMeta: metav1.ObjectMeta{
							UID:       types.UID(uuid.NewUUID()),
							Name:      "guaranteed-pod",
							Namespace: "test",
						},
						Spec: v1.PodSpec{
							Containers: []v1.Container{
								{
									Name:  "foo",
									Image: "busybox",
									Resources: v1.ResourceRequirements{
										Requests: v1.ResourceList{
											v1.ResourceCPU:    resource.MustParse("1"),
											v1.ResourceMemory: resource.MustParse("128Mi"),
										},
										Limits: v1.ResourceList{
											v1.ResourceCPU:    resource.MustParse("1"),
											v1.ResourceMemory: resource.MustParse("128Mi"),
										},
									},
								},
							},
						},
					},
					{
						ObjectMeta: metav1.ObjectMeta{
							UID:       types.UID(uuid.NewUUID()),
							Name:      "burstable-pod",
							Namespace: "test",
						},
						Spec: v1.PodSpec{
							Containers: []v1.Container{
								{
									Name:  "foo",
									Image: "busybox",
									Resources: v1.ResourceRequirements{
										Requests: v1.ResourceList{
											v1.ResourceCPU:    resource.MustParse("1"),
											v1.ResourceMemory: resource.MustParse("128Mi"),
										},