Add status validation unit tests, validate updatedReplicas
This commit is contained in:
@@ -5318,6 +5318,125 @@ func TestValidateService(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateReplicationControllerStatus(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
||||
replicas int32
|
||||
fullyLabeledReplicas int32
|
||||
readyReplicas int32
|
||||
availableReplicas int32
|
||||
observedGeneration int64
|
||||
|
||||
expectedErr bool
|
||||
}{
|
||||
{
|
||||
name: "valid status",
|
||||
replicas: 3,
|
||||
fullyLabeledReplicas: 3,
|
||||
readyReplicas: 2,
|
||||
availableReplicas: 1,
|
||||
observedGeneration: 2,
|
||||
expectedErr: false,
|
||||
},
|
||||
{
|
||||
name: "invalid replicas",
|
||||
replicas: -1,
|
||||
fullyLabeledReplicas: 3,
|
||||
readyReplicas: 2,
|
||||
availableReplicas: 1,
|
||||
observedGeneration: 2,
|
||||
expectedErr: true,
|
||||
},
|
||||
{
|
||||
name: "invalid fullyLabeledReplicas",
|
||||
replicas: 3,
|
||||
fullyLabeledReplicas: -1,
|
||||
readyReplicas: 2,
|
||||
availableReplicas: 1,
|
||||
observedGeneration: 2,
|
||||
expectedErr: true,
|
||||
},
|
||||
{
|
||||
name: "invalid readyReplicas",
|
||||
replicas: 3,
|
||||
fullyLabeledReplicas: 3,
|
||||
readyReplicas: -1,
|
||||
availableReplicas: 1,
|
||||
observedGeneration: 2,
|
||||
expectedErr: true,
|
||||
},
|
||||
{
|
||||
name: "invalid availableReplicas",
|
||||
replicas: 3,
|
||||
fullyLabeledReplicas: 3,
|
||||
readyReplicas: 3,
|
||||
availableReplicas: -1,
|
||||
observedGeneration: 2,
|
||||
expectedErr: true,
|
||||
},
|
||||
{
|
||||
name: "invalid observedGeneration",
|
||||
replicas: 3,
|
||||
fullyLabeledReplicas: 3,
|
||||
readyReplicas: 3,
|
||||
availableReplicas: 3,
|
||||
observedGeneration: -1,
|
||||
expectedErr: true,
|
||||
},
|
||||
{
|
||||
name: "fullyLabeledReplicas greater than replicas",
|
||||
replicas: 3,
|
||||
fullyLabeledReplicas: 4,
|
||||
readyReplicas: 3,
|
||||
availableReplicas: 3,
|
||||
observedGeneration: 1,
|
||||
expectedErr: true,
|
||||
},
|
||||
{
|
||||
name: "readyReplicas greater than replicas",
|
||||
replicas: 3,
|
||||
fullyLabeledReplicas: 3,
|
||||
readyReplicas: 4,
|
||||
availableReplicas: 3,
|
||||
observedGeneration: 1,
|
||||
expectedErr: true,
|
||||
},
|
||||
{
|
||||
name: "availableReplicas greater than replicas",
|
||||
replicas: 3,
|
||||
fullyLabeledReplicas: 3,
|
||||
readyReplicas: 3,
|
||||
availableReplicas: 4,
|
||||
observedGeneration: 1,
|
||||
expectedErr: true,
|
||||
},
|
||||
{
|
||||
name: "availableReplicas greater than readyReplicas",
|
||||
replicas: 3,
|
||||
fullyLabeledReplicas: 3,
|
||||
readyReplicas: 2,
|
||||
availableReplicas: 3,
|
||||
observedGeneration: 1,
|
||||
expectedErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
status := api.ReplicationControllerStatus{
|
||||
Replicas: test.replicas,
|
||||
FullyLabeledReplicas: test.fullyLabeledReplicas,
|
||||
ReadyReplicas: test.readyReplicas,
|
||||
AvailableReplicas: test.availableReplicas,
|
||||
ObservedGeneration: test.observedGeneration,
|
||||
}
|
||||
|
||||
if hasErr := len(ValidateReplicationControllerStatus(status, field.NewPath("status"))) > 0; hasErr != test.expectedErr {
|
||||
t.Errorf("%s: expected error: %t, got error: %t", test.name, test.expectedErr, hasErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateReplicationControllerStatusUpdate(t *testing.T) {
|
||||
validSelector := map[string]string{"a": "b"}
|
||||
validPodTemplate := api.PodTemplate{
|
||||
|
Reference in New Issue
Block a user