Skip to content

Commit

Permalink
Add test to check max length
Browse files Browse the repository at this point in the history
  • Loading branch information
aruiz14 committed Jan 15, 2025
1 parent bdeaae9 commit b99db0f
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions internal/cmd/agent/deployer/monitor/updatestatus_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package monitor

import (
"fmt"
"testing"

fleetv1 "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1/summary"
Expand Down Expand Up @@ -191,6 +192,69 @@ func Test_updateFromResources(t *testing.T) {
assert.NotEmpty(t, status.ModifiedStatus[0].Patch)
},
},
{
name: "non-ready and modified status lists have a max length",
args: args{
resources: func(n int) []fleet.BundleDeploymentResource {
cms := make([]fleet.BundleDeploymentResource, n)
for x := range n {
cms[x] = fleet.BundleDeploymentResource{
Kind: "ConfigMap",
APIVersion: "v1",
Namespace: "testns",
Name: fmt.Sprintf("testcm-%d", x),
}
}
pods := make([]fleet.BundleDeploymentResource, n)
for x := range n {
pods[x] = fleet.BundleDeploymentResource{
Kind: "Pod",
APIVersion: "v1",
Namespace: "testns",
Name: fmt.Sprintf("pod-%d", x),
}
}
return append(cms, pods...)
}(12),
nonReady: func(n int) []fleet.NonReadyStatus {
pods := make([]fleet.NonReadyStatus, n)
for x := range n {
pods[x] = fleet.NonReadyStatus{
Kind: "Pod",
APIVersion: "v1",
Namespace: "testns",
Name: fmt.Sprintf("pod-%d", x),
Summary: fleetv1.Summary{
State: "Evicted",
},
}
}
return pods
}(12),
modified: func(n int) []fleet.ModifiedStatus {
cms := make([]fleet.ModifiedStatus, n)
for x := range n {
cms[x] = fleet.ModifiedStatus{
Kind: "ConfigMap",
APIVersion: "v1",
Namespace: "testns",
Name: fmt.Sprintf("testcm-%d", x),
Create: true,
}
}
return cms
}(12),
},
assert: func(t *testing.T, status fleet.BundleDeploymentStatus) {
assert.Equal(t, status.ResourceCounts, fleet.ResourceCounts{DesiredReady: 24, Missing: 12, NotReady: 12})
assert.Falsef(t, status.Ready, "unexpected ready status")
assert.Falsef(t, status.NonModified, "unexpected non-modified status")
assert.Lenf(t, status.Resources, 24, "unexpected resources length")

assert.Len(t, status.NonReadyStatus, 10, "non-ready status length exceeds maximum")
assert.Len(t, status.ModifiedStatus, 10, "incorrect modified exceeds maximum")
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit b99db0f

Please sign in to comment.