Skip to content

Commit

Permalink
updated testcase of updatestatefulset
Browse files Browse the repository at this point in the history
Signed-off-by: Mahesh Kumar <k.mahesh.9779@gmail.com>
  • Loading branch information
k3mahesh committed Apr 7, 2024
1 parent ae2e340 commit 0d4315c
Showing 1 changed file with 30 additions and 27 deletions.
57 changes: 30 additions & 27 deletions k8sutils/statefulset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,77 +288,80 @@ func TestUpdateStatefulSet(t *testing.T) {
tests := []struct {
name string
sts appsv1.StatefulSet
recreatests bool
updated bool
updatedSts appsv1.StatefulSet
recreateSts bool
stsPresent bool
}{
{
name: "StatefulSet Recreated and Updated",
name: "Update StatefulSet without recreate in existing Statefulset",
sts: appsv1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
Name: "test-sts",
Namespace: "test-ns",
},
},
recreatests: true,
updated: true,
},
{
name: "StatefulSet Updated",
sts: appsv1.StatefulSet{
updatedSts: appsv1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
Name: "test-sts",
Namespace: "test-ns",
},
},
recreatests: false,
updated: true,
recreateSts: false,
stsPresent: true,
},
{
name: "StatefulSet Updated",
name: "Update StatefulSet with recreate in existing Statefulset",
sts: appsv1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
Name: "test-sts",
Namespace: "test-ns",
},
},
recreatests: true,
updated: false,
updatedSts: appsv1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
Name: "test-sts",
Namespace: "test-ns",
},
},
recreateSts: true,
stsPresent: true,
},
{
name: "StatefulSet Updated",
name: "Update StatefulSet, StatefulSet is not present",
sts: appsv1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
Name: "test-sts",
Namespace: "test-ns",
},
},
recreatests: false,
updated: false,
updatedSts: appsv1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
Name: "test-sts",
Namespace: "test-ns",
},
},
recreateSts: false,
stsPresent: false,
},
}

for i := range tests {
test := tests[i]
t.Run(test.name, func(t *testing.T) {
var client *k8sClientFake.Clientset
if test.updated {
if test.stsPresent {
client = k8sClientFake.NewSimpleClientset(test.sts.DeepCopy())
} else {
client = k8sClientFake.NewSimpleClientset()
}
err := updateStatefulSet(test.sts.Namespace, &test.sts, test.recreatests, client)
if test.updated {
if test.recreatests {
err := updateStatefulSet(test.sts.Namespace, &test.updatedSts, test.recreateSts, client)
if test.stsPresent {
if test.recreateSts {
assert.Nil(t, err)
} else {
assert.Nil(t, err)
}
} else {
if test.recreatests {
assert.NotNil(t, err)
} else {
assert.NotNil(t, err)
}
assert.NotNil(t, err)
}
})
}
Expand Down

0 comments on commit 0d4315c

Please sign in to comment.