Merge pull request #56740 from dhilipkumars/UTImprove
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. [Deployments] Move some tests to use go sub-test **What this PR does / why we need it**: **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes # **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
This commit is contained in:
commit
2dc9b1822b
@ -163,13 +163,15 @@ func TestRequeueStuckDeployment(t *testing.T) {
|
|||||||
dc.enqueueDeployment = dc.enqueue
|
dc.enqueueDeployment = dc.enqueue
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
if test.nowFn != nil {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
nowFn = test.nowFn
|
if test.nowFn != nil {
|
||||||
}
|
nowFn = test.nowFn
|
||||||
got := dc.requeueStuckDeployment(test.d, test.status)
|
}
|
||||||
if got != test.expected {
|
got := dc.requeueStuckDeployment(test.d, test.status)
|
||||||
t.Errorf("%s: got duration: %v, expected duration: %v", test.name, got, test.expected)
|
if got != test.expected {
|
||||||
}
|
t.Errorf("%s: got duration: %v, expected duration: %v", test.name, got, test.expected)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -310,32 +312,34 @@ func TestSyncRolloutStatus(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
fake := fake.Clientset{}
|
t.Run(test.name, func(t *testing.T) {
|
||||||
dc := &DeploymentController{
|
fake := fake.Clientset{}
|
||||||
client: &fake,
|
dc := &DeploymentController{
|
||||||
}
|
client: &fake,
|
||||||
|
|
||||||
if test.newRS != nil {
|
|
||||||
test.allRSs = append(test.allRSs, test.newRS)
|
|
||||||
}
|
|
||||||
|
|
||||||
err := dc.syncRolloutStatus(test.allRSs, test.newRS, test.d)
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
newCond := util.GetDeploymentCondition(test.d.Status, test.conditionType)
|
|
||||||
switch {
|
|
||||||
case newCond == nil:
|
|
||||||
if test.d.Spec.ProgressDeadlineSeconds != nil {
|
|
||||||
t.Errorf("%s: expected deployment condition: %s", test.name, test.conditionType)
|
|
||||||
}
|
}
|
||||||
case newCond.Status != test.conditionStatus || newCond.Reason != test.conditionReason:
|
|
||||||
t.Errorf("%s: DeploymentProgressing has status %s with reason %s. Expected %s with %s.", test.name, newCond.Status, newCond.Reason, test.conditionStatus, test.conditionReason)
|
if test.newRS != nil {
|
||||||
case !test.lastUpdate.IsZero() && test.lastUpdate != testTime:
|
test.allRSs = append(test.allRSs, test.newRS)
|
||||||
t.Errorf("%s: LastUpdateTime was changed to %s but expected %s;", test.name, test.lastUpdate, testTime)
|
}
|
||||||
case !test.lastTransition.IsZero() && test.lastTransition != testTime:
|
|
||||||
t.Errorf("%s: LastTransitionTime was changed to %s but expected %s;", test.name, test.lastTransition, testTime)
|
err := dc.syncRolloutStatus(test.allRSs, test.newRS, test.d)
|
||||||
}
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
newCond := util.GetDeploymentCondition(test.d.Status, test.conditionType)
|
||||||
|
switch {
|
||||||
|
case newCond == nil:
|
||||||
|
if test.d.Spec.ProgressDeadlineSeconds != nil {
|
||||||
|
t.Errorf("%s: expected deployment condition: %s", test.name, test.conditionType)
|
||||||
|
}
|
||||||
|
case newCond.Status != test.conditionStatus || newCond.Reason != test.conditionReason:
|
||||||
|
t.Errorf("%s: DeploymentProgressing has status %s with reason %s. Expected %s with %s.", test.name, newCond.Status, newCond.Reason, test.conditionStatus, test.conditionReason)
|
||||||
|
case !test.lastUpdate.IsZero() && test.lastUpdate != testTime:
|
||||||
|
t.Errorf("%s: LastUpdateTime was changed to %s but expected %s;", test.name, test.lastUpdate, testTime)
|
||||||
|
case !test.lastTransition.IsZero() && test.lastTransition != testTime:
|
||||||
|
t.Errorf("%s: LastTransitionTime was changed to %s but expected %s;", test.name, test.lastTransition, testTime)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,9 +115,11 @@ func TestOldPodsRunning(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
if expected, got := test.expected, oldPodsRunning(test.newRS, test.oldRSs, test.podMap); expected != got {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
t.Errorf("%s: expected %t, got %t", test.name, expected, got)
|
if expected, got := test.expected, oldPodsRunning(test.newRS, test.oldRSs, test.podMap); expected != got {
|
||||||
}
|
t.Errorf("%s: expected %t, got %t", test.name, expected, got)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,72 +267,74 @@ func TestScale(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
_ = olderTimestamp
|
t.Run(test.name, func(t *testing.T) {
|
||||||
t.Log(test.name)
|
_ = olderTimestamp
|
||||||
fake := fake.Clientset{}
|
t.Log(test.name)
|
||||||
dc := &DeploymentController{
|
fake := fake.Clientset{}
|
||||||
client: &fake,
|
dc := &DeploymentController{
|
||||||
eventRecorder: &record.FakeRecorder{},
|
client: &fake,
|
||||||
}
|
eventRecorder: &record.FakeRecorder{},
|
||||||
|
|
||||||
if test.newRS != nil {
|
|
||||||
desiredReplicas := *(test.oldDeployment.Spec.Replicas)
|
|
||||||
if desired, ok := test.desiredReplicasAnnotations[test.newRS.Name]; ok {
|
|
||||||
desiredReplicas = desired
|
|
||||||
}
|
}
|
||||||
deploymentutil.SetReplicasAnnotations(test.newRS, desiredReplicas, desiredReplicas+deploymentutil.MaxSurge(*test.oldDeployment))
|
|
||||||
}
|
|
||||||
for i := range test.oldRSs {
|
|
||||||
rs := test.oldRSs[i]
|
|
||||||
if rs == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
desiredReplicas := *(test.oldDeployment.Spec.Replicas)
|
|
||||||
if desired, ok := test.desiredReplicasAnnotations[rs.Name]; ok {
|
|
||||||
desiredReplicas = desired
|
|
||||||
}
|
|
||||||
deploymentutil.SetReplicasAnnotations(rs, desiredReplicas, desiredReplicas+deploymentutil.MaxSurge(*test.oldDeployment))
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := dc.scale(test.deployment, test.newRS, test.oldRSs); err != nil {
|
if test.newRS != nil {
|
||||||
t.Errorf("%s: unexpected error: %v", test.name, err)
|
desiredReplicas := *(test.oldDeployment.Spec.Replicas)
|
||||||
continue
|
if desired, ok := test.desiredReplicasAnnotations[test.newRS.Name]; ok {
|
||||||
}
|
desiredReplicas = desired
|
||||||
|
}
|
||||||
|
deploymentutil.SetReplicasAnnotations(test.newRS, desiredReplicas, desiredReplicas+deploymentutil.MaxSurge(*test.oldDeployment))
|
||||||
|
}
|
||||||
|
for i := range test.oldRSs {
|
||||||
|
rs := test.oldRSs[i]
|
||||||
|
if rs == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
desiredReplicas := *(test.oldDeployment.Spec.Replicas)
|
||||||
|
if desired, ok := test.desiredReplicasAnnotations[rs.Name]; ok {
|
||||||
|
desiredReplicas = desired
|
||||||
|
}
|
||||||
|
deploymentutil.SetReplicasAnnotations(rs, desiredReplicas, desiredReplicas+deploymentutil.MaxSurge(*test.oldDeployment))
|
||||||
|
}
|
||||||
|
|
||||||
// Construct the nameToSize map that will hold all the sizes we got our of tests
|
if err := dc.scale(test.deployment, test.newRS, test.oldRSs); err != nil {
|
||||||
// Skip updating the map if the replica set wasn't updated since there will be
|
t.Errorf("%s: unexpected error: %v", test.name, err)
|
||||||
// no update action for it.
|
return
|
||||||
nameToSize := make(map[string]int32)
|
}
|
||||||
if test.newRS != nil {
|
|
||||||
nameToSize[test.newRS.Name] = *(test.newRS.Spec.Replicas)
|
// Construct the nameToSize map that will hold all the sizes we got our of tests
|
||||||
}
|
// Skip updating the map if the replica set wasn't updated since there will be
|
||||||
for i := range test.oldRSs {
|
// no update action for it.
|
||||||
rs := test.oldRSs[i]
|
nameToSize := make(map[string]int32)
|
||||||
nameToSize[rs.Name] = *(rs.Spec.Replicas)
|
if test.newRS != nil {
|
||||||
}
|
nameToSize[test.newRS.Name] = *(test.newRS.Spec.Replicas)
|
||||||
// Get all the UPDATE actions and update nameToSize with all the updated sizes.
|
}
|
||||||
for _, action := range fake.Actions() {
|
for i := range test.oldRSs {
|
||||||
rs := action.(testclient.UpdateAction).GetObject().(*extensions.ReplicaSet)
|
rs := test.oldRSs[i]
|
||||||
if !test.wasntUpdated[rs.Name] {
|
|
||||||
nameToSize[rs.Name] = *(rs.Spec.Replicas)
|
nameToSize[rs.Name] = *(rs.Spec.Replicas)
|
||||||
}
|
}
|
||||||
}
|
// Get all the UPDATE actions and update nameToSize with all the updated sizes.
|
||||||
|
for _, action := range fake.Actions() {
|
||||||
if test.expectedNew != nil && test.newRS != nil && *(test.expectedNew.Spec.Replicas) != nameToSize[test.newRS.Name] {
|
rs := action.(testclient.UpdateAction).GetObject().(*extensions.ReplicaSet)
|
||||||
t.Errorf("%s: expected new replicas: %d, got: %d", test.name, *(test.expectedNew.Spec.Replicas), nameToSize[test.newRS.Name])
|
if !test.wasntUpdated[rs.Name] {
|
||||||
continue
|
nameToSize[rs.Name] = *(rs.Spec.Replicas)
|
||||||
}
|
}
|
||||||
if len(test.expectedOld) != len(test.oldRSs) {
|
|
||||||
t.Errorf("%s: expected %d old replica sets, got %d", test.name, len(test.expectedOld), len(test.oldRSs))
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
for n := range test.oldRSs {
|
|
||||||
rs := test.oldRSs[n]
|
|
||||||
expected := test.expectedOld[n]
|
|
||||||
if *(expected.Spec.Replicas) != nameToSize[rs.Name] {
|
|
||||||
t.Errorf("%s: expected old (%s) replicas: %d, got: %d", test.name, rs.Name, *(expected.Spec.Replicas), nameToSize[rs.Name])
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
if test.expectedNew != nil && test.newRS != nil && *(test.expectedNew.Spec.Replicas) != nameToSize[test.newRS.Name] {
|
||||||
|
t.Errorf("%s: expected new replicas: %d, got: %d", test.name, *(test.expectedNew.Spec.Replicas), nameToSize[test.newRS.Name])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(test.expectedOld) != len(test.oldRSs) {
|
||||||
|
t.Errorf("%s: expected %d old replica sets, got %d", test.name, len(test.expectedOld), len(test.oldRSs))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for n := range test.oldRSs {
|
||||||
|
rs := test.oldRSs[n]
|
||||||
|
expected := test.expectedOld[n]
|
||||||
|
if *(expected.Spec.Replicas) != nameToSize[rs.Name] {
|
||||||
|
t.Errorf("%s: expected old (%s) replicas: %d, got: %d", test.name, rs.Name, *(expected.Spec.Replicas), nameToSize[rs.Name])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user