Skip to content

Commit 7729b91

Browse files
authored
chore: Add unit test to cover apps health status in an app in any namespace context (argoproj#23693)
Signed-off-by: OpenGuidou <[email protected]>
1 parent 00c731e commit 7729b91

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

server/application/application_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2449,6 +2449,47 @@ func TestInferResourcesStatusHealth(t *testing.T) {
24492449
assert.Nil(t, testApp.Status.Resources[1].Health)
24502450
}
24512451

2452+
func TestInferResourcesStatusHealthWithAppInAnyNamespace(t *testing.T) {
2453+
cacheClient := cache.NewCache(cache.NewInMemoryCache(1 * time.Hour))
2454+
2455+
testApp := newTestApp()
2456+
testApp.Namespace = "otherNamespace"
2457+
testApp.Status.ResourceHealthSource = v1alpha1.ResourceHealthLocationAppTree
2458+
testApp.Status.Resources = []v1alpha1.ResourceStatus{{
2459+
Group: "apps",
2460+
Kind: "Deployment",
2461+
Name: "guestbook",
2462+
Namespace: "otherNamespace",
2463+
}, {
2464+
Group: "apps",
2465+
Kind: "StatefulSet",
2466+
Name: "guestbook-stateful",
2467+
Namespace: "otherNamespace",
2468+
}}
2469+
appServer := newTestAppServer(t, testApp)
2470+
appStateCache := appstate.NewCache(cacheClient, time.Minute)
2471+
err := appStateCache.SetAppResourcesTree("otherNamespace"+"_"+testApp.Name, &v1alpha1.ApplicationTree{Nodes: []v1alpha1.ResourceNode{{
2472+
ResourceRef: v1alpha1.ResourceRef{
2473+
Group: "apps",
2474+
Kind: "Deployment",
2475+
Name: "guestbook",
2476+
Namespace: "otherNamespace",
2477+
},
2478+
Health: &v1alpha1.HealthStatus{
2479+
Status: health.HealthStatusDegraded,
2480+
},
2481+
}}})
2482+
2483+
require.NoError(t, err)
2484+
2485+
appServer.cache = servercache.NewCache(appStateCache, time.Minute, time.Minute)
2486+
2487+
appServer.inferResourcesStatusHealth(testApp)
2488+
2489+
assert.Equal(t, health.HealthStatusDegraded, testApp.Status.Resources[0].Health.Status)
2490+
assert.Nil(t, testApp.Status.Resources[1].Health)
2491+
}
2492+
24522493
func TestRunNewStyleResourceAction(t *testing.T) {
24532494
cacheClient := cache.NewCache(cache.NewInMemoryCache(1 * time.Hour))
24542495

0 commit comments

Comments
 (0)