Skip to content

Commit

Permalink
test: added missing test case for events.go (#1017)
Browse files Browse the repository at this point in the history
With the addition of the latest changes, the missing test case when an
event happens after the currently set latest event has been covered.

Partially Addresses: #889

Signed-off-by: VaibhavMalik4187 <[email protected]>
Co-authored-by: Alex Jones <[email protected]>
  • Loading branch information
VaibhavMalik4187 and AlexsJones authored Mar 21, 2024
1 parent 47463d4 commit ebfbba9
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions pkg/analyzer/pvc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"context"
"sort"
"testing"
"time"

"github.com/k8sgpt-ai/k8sgpt/pkg/common"
"github.com/k8sgpt-ai/k8sgpt/pkg/kubernetes"
Expand All @@ -38,13 +39,15 @@ func TestPersistentVolumeClaimAnalyzer(t *testing.T) {
Client: &kubernetes.Client{
Client: fake.NewSimpleClientset(
&appsv1.Event{
// This is the latest event.
ObjectMeta: metav1.ObjectMeta{
Name: "Event1",
Namespace: "default",
},
LastTimestamp: metav1.Time{
Time: time.Date(2024, 3, 15, 10, 0, 0, 0, time.UTC),
},
Reason: "ProvisioningFailed",
Message: "PVC provisioning failed",
Message: "PVC Event1 provisioning failed",
},
&appsv1.Event{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -54,10 +57,16 @@ func TestPersistentVolumeClaimAnalyzer(t *testing.T) {
},
},
&appsv1.Event{
// This is the latest event.
ObjectMeta: metav1.ObjectMeta{
Name: "Event3",
Namespace: "default",
},
LastTimestamp: metav1.Time{
Time: time.Date(2024, 4, 15, 10, 0, 0, 0, time.UTC),
},
Reason: "ProvisioningFailed",
Message: "PVC Event3 provisioning failed",
},
&appsv1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -214,9 +223,6 @@ func TestPersistentVolumeClaimAnalyzer(t *testing.T) {

for i, expectation := range tt.expectations {
require.Equal(t, expectation, results[i].Name)
for _, failure := range results[i].Error {
require.Equal(t, "PVC provisioning failed", failure.Text)
}
}
}
})
Expand Down

0 comments on commit ebfbba9

Please sign in to comment.