Move some tests to use go sub-test

This commit is contained in:
dhilipkumars 2017-12-02 12:47:31 +05:30
parent 8c1ee761d2
commit 623d7c42ac
3 changed files with 104 additions and 96 deletions

View File

@ -163,6 +163,7 @@ func TestRequeueStuckDeployment(t *testing.T) {
dc.enqueueDeployment = dc.enqueue dc.enqueueDeployment = dc.enqueue
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
if test.nowFn != nil { if test.nowFn != nil {
nowFn = test.nowFn nowFn = test.nowFn
} }
@ -170,6 +171,7 @@ func TestRequeueStuckDeployment(t *testing.T) {
if got != test.expected { if got != test.expected {
t.Errorf("%s: got duration: %v, expected duration: %v", test.name, got, test.expected) t.Errorf("%s: got duration: %v, expected duration: %v", test.name, got, test.expected)
} }
})
} }
} }
@ -310,6 +312,7 @@ func TestSyncRolloutStatus(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
fake := fake.Clientset{} fake := fake.Clientset{}
dc := &DeploymentController{ dc := &DeploymentController{
client: &fake, client: &fake,
@ -337,5 +340,6 @@ func TestSyncRolloutStatus(t *testing.T) {
case !test.lastTransition.IsZero() && test.lastTransition != testTime: case !test.lastTransition.IsZero() && test.lastTransition != testTime:
t.Errorf("%s: LastTransitionTime was changed to %s but expected %s;", test.name, test.lastTransition, testTime) t.Errorf("%s: LastTransitionTime was changed to %s but expected %s;", test.name, test.lastTransition, testTime)
} }
})
} }
} }

View File

@ -115,9 +115,11 @@ func TestOldPodsRunning(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
if expected, got := test.expected, oldPodsRunning(test.newRS, test.oldRSs, test.podMap); 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) t.Errorf("%s: expected %t, got %t", test.name, expected, got)
} }
})
} }
} }

View File

@ -267,6 +267,7 @@ func TestScale(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
_ = olderTimestamp _ = olderTimestamp
t.Log(test.name) t.Log(test.name)
fake := fake.Clientset{} fake := fake.Clientset{}
@ -296,7 +297,7 @@ func TestScale(t *testing.T) {
if err := dc.scale(test.deployment, test.newRS, test.oldRSs); err != nil { if err := dc.scale(test.deployment, test.newRS, test.oldRSs); err != nil {
t.Errorf("%s: unexpected error: %v", test.name, err) t.Errorf("%s: unexpected error: %v", test.name, err)
continue return
} }
// Construct the nameToSize map that will hold all the sizes we got our of tests // Construct the nameToSize map that will hold all the sizes we got our of tests
@ -320,11 +321,11 @@ func TestScale(t *testing.T) {
if test.expectedNew != nil && test.newRS != nil && *(test.expectedNew.Spec.Replicas) != nameToSize[test.newRS.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]) t.Errorf("%s: expected new replicas: %d, got: %d", test.name, *(test.expectedNew.Spec.Replicas), nameToSize[test.newRS.Name])
continue return
} }
if len(test.expectedOld) != len(test.oldRSs) { 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)) t.Errorf("%s: expected %d old replica sets, got %d", test.name, len(test.expectedOld), len(test.oldRSs))
continue return
} }
for n := range test.oldRSs { for n := range test.oldRSs {
rs := test.oldRSs[n] rs := test.oldRSs[n]
@ -333,6 +334,7 @@ func TestScale(t *testing.T) {
t.Errorf("%s: expected old (%s) replicas: %d, got: %d", test.name, rs.Name, *(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])
} }
} }
})
} }
} }