generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: updated conditions to check for readiness of deployment
- Loading branch information
Showing
2 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package eventing | ||
|
||
import ( | ||
Check failure on line 3 in internal/controller/operator/eventing/status_test.go GitHub Actions / Run golangci-lint
|
||
"github.com/stretchr/testify/require" | ||
kappsv1 "k8s.io/api/apps/v1" | ||
"k8s.io/utils/ptr" | ||
"testing" | ||
Check failure on line 7 in internal/controller/operator/eventing/status_test.go GitHub Actions / Run golangci-lint
|
||
) | ||
|
||
func Test_IsDeploymentReady(t *testing.T) { | ||
t.Parallel() | ||
|
||
// define test cases | ||
testCases := []struct { | ||
name string | ||
givenDeployment *kappsv1.Deployment | ||
wantResult bool | ||
}{ | ||
{ | ||
name: "should return false when all replicas are not updated", | ||
givenDeployment: &kappsv1.Deployment{ | ||
Spec: kappsv1.DeploymentSpec{Replicas: ptr.To[int32](2)}, | ||
Status: kappsv1.DeploymentStatus{ | ||
Replicas: 2, | ||
UpdatedReplicas: 1, | ||
AvailableReplicas: 2, | ||
ReadyReplicas: 2, | ||
}, | ||
}, | ||
wantResult: false, | ||
}, | ||
{ | ||
name: "should return false when all replicas are not updated", | ||
givenDeployment: &kappsv1.Deployment{ | ||
Spec: kappsv1.DeploymentSpec{Replicas: ptr.To[int32](2)}, | ||
Status: kappsv1.DeploymentStatus{ | ||
Replicas: 2, | ||
UpdatedReplicas: 1, | ||
AvailableReplicas: 2, | ||
ReadyReplicas: 2, | ||
}, | ||
}, | ||
wantResult: false, | ||
}, | ||
{ | ||
name: "should return false when all replicas are not available", | ||
givenDeployment: &kappsv1.Deployment{ | ||
Spec: kappsv1.DeploymentSpec{Replicas: ptr.To[int32](2)}, | ||
Status: kappsv1.DeploymentStatus{ | ||
Replicas: 2, | ||
UpdatedReplicas: 2, | ||
AvailableReplicas: 1, | ||
ReadyReplicas: 2, | ||
}, | ||
}, | ||
wantResult: false, | ||
}, | ||
{ | ||
name: "should return false when all replicas are not ready", | ||
givenDeployment: &kappsv1.Deployment{ | ||
Spec: kappsv1.DeploymentSpec{Replicas: ptr.To[int32](2)}, | ||
Status: kappsv1.DeploymentStatus{ | ||
Replicas: 2, | ||
UpdatedReplicas: 2, | ||
AvailableReplicas: 2, | ||
ReadyReplicas: 1, | ||
}, | ||
}, | ||
wantResult: false, | ||
}, | ||
{ | ||
name: "should return true when all replicas are ready", | ||
givenDeployment: &kappsv1.Deployment{ | ||
Spec: kappsv1.DeploymentSpec{Replicas: ptr.To[int32](2)}, | ||
Status: kappsv1.DeploymentStatus{ | ||
Replicas: 2, | ||
UpdatedReplicas: 2, | ||
AvailableReplicas: 2, | ||
ReadyReplicas: 2, | ||
}, | ||
}, | ||
wantResult: true, | ||
}, | ||
} | ||
|
||
// run test cases | ||
for _, tc := range testCases { | ||
testcase := tc | ||
t.Run(testcase.name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
// when | ||
result := IsDeploymentReady(testcase.givenDeployment) | ||
|
||
// then | ||
require.Equal(t, testcase.wantResult, result) | ||
}) | ||
} | ||
} |