Skip to content

Commit

Permalink
UPSTREAM: <carry>: openshift: shorten test helper names
Browse files Browse the repository at this point in the history
Shorten the test helper function names that create spec and configs
for the unit tests. They previously had `must` as part of the name but
they don't actually fail and/or return any error.
  • Loading branch information
frobware committed Apr 4, 2019
1 parent 42607d7 commit 1a6228b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,23 @@ func mustCreateTestController(t *testing.T, testConfigs ...*testConfig) (*machin
}
}

func mustCreateMachineSetTestConfig(namespace string, nodeCount int, replicaCount int32, annotations map[string]string) *testConfig {
return mustCreateTestConfigs(mustCreateTestSpecs(namespace, 1, nodeCount, replicaCount, false, annotations)...)[0]
func createMachineSetTestConfig(namespace string, nodeCount int, replicaCount int32, annotations map[string]string) *testConfig {
return createTestConfigs(createTestSpecs(namespace, 1, nodeCount, replicaCount, false, annotations)...)[0]
}

func mustCreateMachineSetTestConfigs(namespace string, configCount, nodeCount int, replicaCount int32, annotations map[string]string) []*testConfig {
return mustCreateTestConfigs(mustCreateTestSpecs(namespace, configCount, nodeCount, replicaCount, false, annotations)...)
func createMachineSetTestConfigs(namespace string, configCount, nodeCount int, replicaCount int32, annotations map[string]string) []*testConfig {
return createTestConfigs(createTestSpecs(namespace, configCount, nodeCount, replicaCount, false, annotations)...)
}

func mustCreateMachineDeploymentTestConfig(namespace string, nodeCount int, replicaCount int32, annotations map[string]string) *testConfig {
return mustCreateTestConfigs(mustCreateTestSpecs(namespace, 1, nodeCount, replicaCount, true, annotations)...)[0]
func createMachineDeploymentTestConfig(namespace string, nodeCount int, replicaCount int32, annotations map[string]string) *testConfig {
return createTestConfigs(createTestSpecs(namespace, 1, nodeCount, replicaCount, true, annotations)...)[0]
}

func mustCreateMachineDeploymentTestConfigs(namespace string, configCount, nodeCount int, replicaCount int32, annotations map[string]string) []*testConfig {
return mustCreateTestConfigs(mustCreateTestSpecs(namespace, configCount, nodeCount, replicaCount, true, annotations)...)
func createMachineDeploymentTestConfigs(namespace string, configCount, nodeCount int, replicaCount int32, annotations map[string]string) []*testConfig {
return createTestConfigs(createTestSpecs(namespace, configCount, nodeCount, replicaCount, true, annotations)...)
}

func mustCreateTestSpecs(namespace string, scalableResourceCount, nodeCount int, replicaCount int32, isMachineDeployment bool, annotations map[string]string) []testSpec {
func createTestSpecs(namespace string, scalableResourceCount, nodeCount int, replicaCount int32, isMachineDeployment bool, annotations map[string]string) []testSpec {
var specs []testSpec

for i := 0; i < scalableResourceCount; i++ {
Expand All @@ -126,7 +126,7 @@ func mustCreateTestSpecs(namespace string, scalableResourceCount, nodeCount int,
return specs
}

func mustCreateTestConfigs(specs ...testSpec) []*testConfig {
func createTestConfigs(specs ...testSpec) []*testConfig {
var result []*testConfig

for i, spec := range specs {
Expand Down Expand Up @@ -336,7 +336,7 @@ func TestControllerFindMachineByID(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
testConfig := mustCreateMachineSetTestConfig(testNamespace, 1, 1, map[string]string{
testConfig := createMachineSetTestConfig(testNamespace, 1, 1, map[string]string{
nodeGroupMinSizeAnnotationKey: "1",
nodeGroupMaxSizeAnnotationKey: "10",
})
Expand All @@ -352,7 +352,7 @@ func TestControllerFindMachineByID(t *testing.T) {
}

func TestControllerFindMachineOwner(t *testing.T) {
testConfig := mustCreateMachineSetTestConfig(testNamespace, 1, 1, map[string]string{
testConfig := createMachineSetTestConfig(testNamespace, 1, 1, map[string]string{
nodeGroupMinSizeAnnotationKey: "1",
nodeGroupMaxSizeAnnotationKey: "10",
})
Expand Down Expand Up @@ -397,7 +397,7 @@ func TestControllerFindMachineOwner(t *testing.T) {
}

func TestControllerFindMachineByNodeProviderID(t *testing.T) {
testConfig := mustCreateMachineSetTestConfig(testNamespace, 1, 1, map[string]string{
testConfig := createMachineSetTestConfig(testNamespace, 1, 1, map[string]string{
nodeGroupMinSizeAnnotationKey: "1",
nodeGroupMaxSizeAnnotationKey: "10",
})
Expand Down Expand Up @@ -446,7 +446,7 @@ func TestControllerFindMachineByNodeProviderID(t *testing.T) {
}

func TestControllerFindNodeByNodeName(t *testing.T) {
testConfig := mustCreateMachineSetTestConfig(testNamespace, 1, 1, map[string]string{
testConfig := createMachineSetTestConfig(testNamespace, 1, 1, map[string]string{
nodeGroupMinSizeAnnotationKey: "1",
nodeGroupMaxSizeAnnotationKey: "10",
})
Expand Down Expand Up @@ -474,7 +474,7 @@ func TestControllerFindNodeByNodeName(t *testing.T) {
}

func TestControllerMachinesInMachineSet(t *testing.T) {
testConfig1 := mustCreateMachineSetTestConfig("testConfig1", 5, 5, map[string]string{
testConfig1 := createMachineSetTestConfig("testConfig1", 5, 5, map[string]string{
nodeGroupMinSizeAnnotationKey: "1",
nodeGroupMaxSizeAnnotationKey: "10",
})
Expand All @@ -486,7 +486,7 @@ func TestControllerMachinesInMachineSet(t *testing.T) {
// nodes and the additional machineset to the existing set of
// test objects in the controller. This gives us two
// machinesets, each with their own machines and linked nodes.
testConfig2 := mustCreateMachineSetTestConfig("testConfig2", 5, 5, map[string]string{
testConfig2 := createMachineSetTestConfig("testConfig2", 5, 5, map[string]string{
nodeGroupMinSizeAnnotationKey: "1",
nodeGroupMaxSizeAnnotationKey: "10",
})
Expand Down Expand Up @@ -547,7 +547,7 @@ func TestControllerMachinesInMachineSet(t *testing.T) {
}

func TestControllerLookupNodeGroupForNonExistentNode(t *testing.T) {
testConfig := mustCreateMachineSetTestConfig(testNamespace, 1, 1, map[string]string{
testConfig := createMachineSetTestConfig(testNamespace, 1, 1, map[string]string{
nodeGroupMinSizeAnnotationKey: "1",
nodeGroupMaxSizeAnnotationKey: "10",
})
Expand Down Expand Up @@ -593,15 +593,15 @@ func TestControllerNodeGroupForNodeWithMissingMachineOwner(t *testing.T) {
}

t.Run("MachineSet", func(t *testing.T) {
testConfig := mustCreateMachineSetTestConfig(testNamespace, 1, 1, map[string]string{
testConfig := createMachineSetTestConfig(testNamespace, 1, 1, map[string]string{
nodeGroupMinSizeAnnotationKey: "1",
nodeGroupMaxSizeAnnotationKey: "10",
})
test(t, testConfig)
})

t.Run("MachineDeployment", func(t *testing.T) {
testConfig := mustCreateMachineDeploymentTestConfig(testNamespace, 1, 1, map[string]string{
testConfig := createMachineDeploymentTestConfig(testNamespace, 1, 1, map[string]string{
nodeGroupMinSizeAnnotationKey: "1",
nodeGroupMaxSizeAnnotationKey: "10",
})
Expand All @@ -626,15 +626,15 @@ func TestControllerNodeGroupForNodeWithPositiveScalingBounds(t *testing.T) {
}

t.Run("MachineSet", func(t *testing.T) {
testConfig := mustCreateMachineSetTestConfig(testNamespace, 1, 1, map[string]string{
testConfig := createMachineSetTestConfig(testNamespace, 1, 1, map[string]string{
nodeGroupMinSizeAnnotationKey: "1",
nodeGroupMaxSizeAnnotationKey: "1",
})
test(t, testConfig)
})

t.Run("MachineDeployment", func(t *testing.T) {
testConfig := mustCreateMachineDeploymentTestConfig(testNamespace, 1, 1, map[string]string{
testConfig := createMachineDeploymentTestConfig(testNamespace, 1, 1, map[string]string{
nodeGroupMinSizeAnnotationKey: "1",
nodeGroupMaxSizeAnnotationKey: "1",
})
Expand Down Expand Up @@ -666,14 +666,14 @@ func TestControllerNodeGroups(t *testing.T) {
assertNodegroupLen(t, controller, 0)

// Test #2: add 5 machineset-based nodegroups
machineSetConfigs := mustCreateMachineSetTestConfigs("MachineSet", 5, 1, 1, annotations)
machineSetConfigs := createMachineSetTestConfigs("MachineSet", 5, 1, 1, annotations)
if err := addTestConfigs(t, controller, machineSetConfigs...); err != nil {
t.Fatalf("unexpected error: %v", err)
}
assertNodegroupLen(t, controller, 5)

// Test #2: add 2 machinedeployment-based nodegroups
machineDeploymentConfigs := mustCreateMachineDeploymentTestConfigs("MachineDeployment", 2, 1, 1, annotations)
machineDeploymentConfigs := createMachineDeploymentTestConfigs("MachineDeployment", 2, 1, 1, annotations)
if err := addTestConfigs(t, controller, machineDeploymentConfigs...); err != nil {
t.Fatalf("unexpected error: %v", err)
}
Expand All @@ -697,14 +697,14 @@ func TestControllerNodeGroups(t *testing.T) {
}

// Test #5: machineset with no scaling bounds results in no nodegroups
machineSetConfigs = mustCreateMachineSetTestConfigs("MachineSet", 5, 1, 1, annotations)
machineSetConfigs = createMachineSetTestConfigs("MachineSet", 5, 1, 1, annotations)
if err := addTestConfigs(t, controller, machineSetConfigs...); err != nil {
t.Fatalf("unexpected error: %v", err)
}
assertNodegroupLen(t, controller, 0)

// Test #6: machinedeployment with no scaling bounds results in no nodegroups
machineDeploymentConfigs = mustCreateMachineDeploymentTestConfigs("MachineDeployment", 2, 1, 1, annotations)
machineDeploymentConfigs = createMachineDeploymentTestConfigs("MachineDeployment", 2, 1, 1, annotations)
if err := addTestConfigs(t, controller, machineDeploymentConfigs...); err != nil {
t.Fatalf("unexpected error: %v", err)
}
Expand All @@ -716,7 +716,7 @@ func TestControllerNodeGroups(t *testing.T) {
}

// Test #7: machineset with bad scaling bounds results in an error and no nodegroups
machineSetConfigs = mustCreateMachineSetTestConfigs("MachineSet", 5, 1, 1, annotations)
machineSetConfigs = createMachineSetTestConfigs("MachineSet", 5, 1, 1, annotations)
if err := addTestConfigs(t, controller, machineSetConfigs...); err != nil {
t.Fatalf("unexpected error: %v", err)
}
Expand All @@ -725,7 +725,7 @@ func TestControllerNodeGroups(t *testing.T) {
}

// Test #8: machinedeployment with bad scaling bounds results in an error and no nodegroups
machineDeploymentConfigs = mustCreateMachineDeploymentTestConfigs("MachineDeployment", 2, 1, 1, annotations)
machineDeploymentConfigs = createMachineDeploymentTestConfigs("MachineDeployment", 2, 1, 1, annotations)
if err := addTestConfigs(t, controller, machineDeploymentConfigs...); err != nil {
t.Fatalf("unexpected error: %v", err)
}
Expand Down Expand Up @@ -781,13 +781,13 @@ func TestControllerNodeGroupsNodeCount(t *testing.T) {

t.Run("MachineSet", func(t *testing.T) {
for _, tc := range testCases {
test(t, tc, mustCreateMachineSetTestConfigs(testNamespace, tc.nodeGroups, tc.nodesPerGroup, int32(tc.nodesPerGroup), annotations))
test(t, tc, createMachineSetTestConfigs(testNamespace, tc.nodeGroups, tc.nodesPerGroup, int32(tc.nodesPerGroup), annotations))
}
})

t.Run("MachineDeployment", func(t *testing.T) {
for _, tc := range testCases {
test(t, tc, mustCreateMachineDeploymentTestConfigs(testNamespace, tc.nodeGroups, tc.nodesPerGroup, int32(tc.nodesPerGroup), annotations))
test(t, tc, createMachineDeploymentTestConfigs(testNamespace, tc.nodeGroups, tc.nodesPerGroup, int32(tc.nodesPerGroup), annotations))
}
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,15 @@ func TestNodeGroupNewNodeGroupConstructor(t *testing.T) {
t.Run("MachineSet", func(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
test(t, tc, mustCreateMachineSetTestConfig(testNamespace, tc.nodeCount, tc.replicas, tc.annotations))
test(t, tc, createMachineSetTestConfig(testNamespace, tc.nodeCount, tc.replicas, tc.annotations))
})
}
})

t.Run("MachineDeployment", func(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
test(t, tc, mustCreateMachineDeploymentTestConfig(testNamespace, tc.nodeCount, tc.replicas, tc.annotations))
test(t, tc, createMachineDeploymentTestConfig(testNamespace, tc.nodeCount, tc.replicas, tc.annotations))
})
}
})
Expand Down Expand Up @@ -296,7 +296,7 @@ func TestNodeGroupIncreaseSizeErrors(t *testing.T) {
nodeGroupMinSizeAnnotationKey: "1",
nodeGroupMaxSizeAnnotationKey: "10",
}
test(t, &tc, mustCreateMachineSetTestConfig(testNamespace, int(tc.initial), tc.initial, annotations))
test(t, &tc, createMachineSetTestConfig(testNamespace, int(tc.initial), tc.initial, annotations))
})
}
})
Expand All @@ -308,7 +308,7 @@ func TestNodeGroupIncreaseSizeErrors(t *testing.T) {
nodeGroupMinSizeAnnotationKey: "1",
nodeGroupMaxSizeAnnotationKey: "10",
}
test(t, &tc, mustCreateMachineDeploymentTestConfig(testNamespace, int(tc.initial), tc.initial, annotations))
test(t, &tc, createMachineDeploymentTestConfig(testNamespace, int(tc.initial), tc.initial, annotations))
})
}
})
Expand Down Expand Up @@ -385,7 +385,7 @@ func TestNodeGroupIncreaseSize(t *testing.T) {
expected: 4,
delta: 1,
}
test(t, &tc, mustCreateMachineSetTestConfig(testNamespace, int(tc.initial), tc.initial, annotations))
test(t, &tc, createMachineSetTestConfig(testNamespace, int(tc.initial), tc.initial, annotations))
})

t.Run("MachineDeployment", func(t *testing.T) {
Expand All @@ -395,7 +395,7 @@ func TestNodeGroupIncreaseSize(t *testing.T) {
expected: 4,
delta: 1,
}
test(t, &tc, mustCreateMachineDeploymentTestConfig(testNamespace, int(tc.initial), tc.initial, annotations))
test(t, &tc, createMachineDeploymentTestConfig(testNamespace, int(tc.initial), tc.initial, annotations))
})
}

Expand Down Expand Up @@ -477,7 +477,7 @@ func TestNodeGroupDecreaseTargetSize(t *testing.T) {
expected: 2,
delta: -1,
}
test(t, &tc, mustCreateMachineSetTestConfig(testNamespace, int(tc.initial), tc.initial, annotations))
test(t, &tc, createMachineSetTestConfig(testNamespace, int(tc.initial), tc.initial, annotations))
})

t.Run("MachineDeployment", func(t *testing.T) {
Expand All @@ -487,7 +487,7 @@ func TestNodeGroupDecreaseTargetSize(t *testing.T) {
expected: 2,
delta: -1,
}
test(t, &tc, mustCreateMachineDeploymentTestConfig(testNamespace, int(tc.initial), tc.initial, annotations))
test(t, &tc, createMachineDeploymentTestConfig(testNamespace, int(tc.initial), tc.initial, annotations))
})
}

Expand Down Expand Up @@ -580,7 +580,7 @@ func TestNodeGroupDecreaseSizeErrors(t *testing.T) {
nodeGroupMinSizeAnnotationKey: "1",
nodeGroupMaxSizeAnnotationKey: "10",
}
test(t, &tc, mustCreateMachineSetTestConfig(testNamespace, int(tc.initial), tc.initial, annotations))
test(t, &tc, createMachineSetTestConfig(testNamespace, int(tc.initial), tc.initial, annotations))
})
}
})
Expand All @@ -592,7 +592,7 @@ func TestNodeGroupDecreaseSizeErrors(t *testing.T) {
nodeGroupMinSizeAnnotationKey: "1",
nodeGroupMaxSizeAnnotationKey: "10",
}
test(t, &tc, mustCreateMachineDeploymentTestConfig(testNamespace, int(tc.initial), tc.initial, annotations))
test(t, &tc, createMachineDeploymentTestConfig(testNamespace, int(tc.initial), tc.initial, annotations))
})
}
})
Expand Down Expand Up @@ -674,14 +674,14 @@ func TestNodeGroupDeleteNodes(t *testing.T) {
// sorting and the expected semantics in test() will fail.

t.Run("MachineSet", func(t *testing.T) {
test(t, mustCreateMachineSetTestConfig(testNamespace, 10, 10, map[string]string{
test(t, createMachineSetTestConfig(testNamespace, 10, 10, map[string]string{
nodeGroupMinSizeAnnotationKey: "1",
nodeGroupMaxSizeAnnotationKey: "10",
}))
})

t.Run("MachineDeployment", func(t *testing.T) {
test(t, mustCreateMachineDeploymentTestConfig(testNamespace, 10, 10, map[string]string{
test(t, createMachineDeploymentTestConfig(testNamespace, 10, 10, map[string]string{
nodeGroupMinSizeAnnotationKey: "1",
nodeGroupMaxSizeAnnotationKey: "10",
}))
Expand Down Expand Up @@ -762,14 +762,14 @@ func TestNodeGroupMachineSetDeleteNodesWithMismatchedNodes(t *testing.T) {
}

t.Run("MachineSet", func(t *testing.T) {
testConfig0 := mustCreateMachineSetTestConfigs(testNamespace+"0", 1, 2, 2, annotations)
testConfig1 := mustCreateMachineSetTestConfigs(testNamespace+"1", 1, 2, 2, annotations)
testConfig0 := createMachineSetTestConfigs(testNamespace+"0", 1, 2, 2, annotations)
testConfig1 := createMachineSetTestConfigs(testNamespace+"1", 1, 2, 2, annotations)
test(t, 2, append(testConfig0, testConfig1...))
})

t.Run("MachineDeployment", func(t *testing.T) {
testConfig0 := mustCreateMachineDeploymentTestConfigs(testNamespace+"0", 1, 2, 2, annotations)
testConfig1 := mustCreateMachineDeploymentTestConfigs(testNamespace+"1", 1, 2, 2, annotations)
testConfig0 := createMachineDeploymentTestConfigs(testNamespace+"0", 1, 2, 2, annotations)
testConfig1 := createMachineDeploymentTestConfigs(testNamespace+"1", 1, 2, 2, annotations)
test(t, 2, append(testConfig0, testConfig1...))
})
}

0 comments on commit 1a6228b

Please sign in to comment.