-
Notifications
You must be signed in to change notification settings - Fork 6.4k
chore(tests): add unit tests for isAppHealthy of ApplicationSet #24487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ranakan19
wants to merge
4
commits into
argoproj:master
Choose a base branch
from
ranakan19:appsetCache
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
965286e
add unit tests for isApplicationHealthy
ranakan19 e7b4cab
Merge branch 'master' of https://github.com/argoproj/argo-cd into app…
ranakan19 3460a65
Merge branch 'master' into appsetCache
ranakan19 56f3078
Merge branch 'master' into appsetCache
ranakan19 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 | ||||
---|---|---|---|---|---|---|
|
@@ -7650,3 +7650,276 @@ func TestIsRollingSyncDeletionReversed(t *testing.T) { | |||||
}) | ||||||
} | ||||||
} | ||||||
|
||||||
func TestIsApplicationHealthy(t *testing.T) { | ||||||
tests := []struct { | ||||||
name string | ||||||
app v1alpha1.Application | ||||||
expectedResult bool | ||||||
}{ | ||||||
{ | ||||||
name: "healthy application with synced status and succeeded operation", | ||||||
app: v1alpha1.Application{ | ||||||
Status: v1alpha1.ApplicationStatus{ | ||||||
Health: v1alpha1.AppHealthStatus{ | ||||||
Status: health.HealthStatusHealthy, | ||||||
}, | ||||||
Sync: v1alpha1.SyncStatus{ | ||||||
Status: v1alpha1.SyncStatusCodeSynced, | ||||||
}, | ||||||
OperationState: &v1alpha1.OperationState{ | ||||||
Phase: common.OperationSucceeded, | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
expectedResult: true, | ||||||
}, | ||||||
{ | ||||||
name: "healthy application with synced status and no operation", | ||||||
app: v1alpha1.Application{ | ||||||
Status: v1alpha1.ApplicationStatus{ | ||||||
Health: v1alpha1.AppHealthStatus{ | ||||||
Status: health.HealthStatusHealthy, | ||||||
}, | ||||||
Sync: v1alpha1.SyncStatus{ | ||||||
Status: v1alpha1.SyncStatusCodeSynced, | ||||||
}, | ||||||
OperationState: nil, | ||||||
}, | ||||||
}, | ||||||
expectedResult: true, | ||||||
}, | ||||||
{ | ||||||
name: "healthy application with unknown sync status and succeeded operation", | ||||||
app: v1alpha1.Application{ | ||||||
Status: v1alpha1.ApplicationStatus{ | ||||||
Health: v1alpha1.AppHealthStatus{ | ||||||
Status: health.HealthStatusHealthy, | ||||||
}, | ||||||
Sync: v1alpha1.SyncStatus{ | ||||||
Status: v1alpha1.SyncStatusCodeUnknown, | ||||||
}, | ||||||
OperationState: &v1alpha1.OperationState{ | ||||||
Phase: common.OperationSucceeded, | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
expectedResult: true, | ||||||
}, | ||||||
{ | ||||||
name: "degraded health status", | ||||||
app: v1alpha1.Application{ | ||||||
Status: v1alpha1.ApplicationStatus{ | ||||||
Health: v1alpha1.AppHealthStatus{ | ||||||
Status: health.HealthStatusDegraded, | ||||||
}, | ||||||
Sync: v1alpha1.SyncStatus{ | ||||||
Status: v1alpha1.SyncStatusCodeSynced, | ||||||
}, | ||||||
OperationState: &v1alpha1.OperationState{ | ||||||
Phase: common.OperationSucceeded, | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
expectedResult: false, | ||||||
}, | ||||||
{ | ||||||
name: "progressing health status", | ||||||
app: v1alpha1.Application{ | ||||||
Status: v1alpha1.ApplicationStatus{ | ||||||
Health: v1alpha1.AppHealthStatus{ | ||||||
Status: health.HealthStatusProgressing, | ||||||
}, | ||||||
Sync: v1alpha1.SyncStatus{ | ||||||
Status: v1alpha1.SyncStatusCodeSynced, | ||||||
}, | ||||||
OperationState: &v1alpha1.OperationState{ | ||||||
Phase: common.OperationSucceeded, | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
expectedResult: false, | ||||||
}, | ||||||
{ | ||||||
name: "missing health status", | ||||||
app: v1alpha1.Application{ | ||||||
Status: v1alpha1.ApplicationStatus{ | ||||||
Health: v1alpha1.AppHealthStatus{ | ||||||
Status: health.HealthStatusMissing, | ||||||
}, | ||||||
Sync: v1alpha1.SyncStatus{ | ||||||
Status: v1alpha1.SyncStatusCodeSynced, | ||||||
}, | ||||||
OperationState: &v1alpha1.OperationState{ | ||||||
Phase: common.OperationSucceeded, | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
expectedResult: false, | ||||||
}, | ||||||
{ | ||||||
name: "unknown health status", | ||||||
app: v1alpha1.Application{ | ||||||
Status: v1alpha1.ApplicationStatus{ | ||||||
Health: v1alpha1.AppHealthStatus{ | ||||||
Status: health.HealthStatusUnknown, | ||||||
}, | ||||||
Sync: v1alpha1.SyncStatus{ | ||||||
Status: v1alpha1.SyncStatusCodeSynced, | ||||||
}, | ||||||
OperationState: &v1alpha1.OperationState{ | ||||||
Phase: common.OperationSucceeded, | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
expectedResult: false, | ||||||
}, | ||||||
{ | ||||||
name: "healthy but out of sync", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I don't know where it would be suitable, but we should mention somewhere that a healthy status doesn't confirm that an application is healthy. |
||||||
app: v1alpha1.Application{ | ||||||
Status: v1alpha1.ApplicationStatus{ | ||||||
Health: v1alpha1.AppHealthStatus{ | ||||||
Status: health.HealthStatusHealthy, | ||||||
}, | ||||||
Sync: v1alpha1.SyncStatus{ | ||||||
Status: v1alpha1.SyncStatusCodeOutOfSync, | ||||||
}, | ||||||
OperationState: &v1alpha1.OperationState{ | ||||||
Phase: common.OperationSucceeded, | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
expectedResult: false, | ||||||
}, | ||||||
{ | ||||||
name: "healthy and synced but operation running", | ||||||
app: v1alpha1.Application{ | ||||||
Status: v1alpha1.ApplicationStatus{ | ||||||
Health: v1alpha1.AppHealthStatus{ | ||||||
Status: health.HealthStatusHealthy, | ||||||
}, | ||||||
Sync: v1alpha1.SyncStatus{ | ||||||
Status: v1alpha1.SyncStatusCodeSynced, | ||||||
}, | ||||||
OperationState: &v1alpha1.OperationState{ | ||||||
Phase: common.OperationRunning, | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
expectedResult: false, | ||||||
}, | ||||||
{ | ||||||
name: "healthy and synced but operation failed", | ||||||
app: v1alpha1.Application{ | ||||||
Status: v1alpha1.ApplicationStatus{ | ||||||
Health: v1alpha1.AppHealthStatus{ | ||||||
Status: health.HealthStatusHealthy, | ||||||
}, | ||||||
Sync: v1alpha1.SyncStatus{ | ||||||
Status: v1alpha1.SyncStatusCodeSynced, | ||||||
}, | ||||||
OperationState: &v1alpha1.OperationState{ | ||||||
Phase: common.OperationFailed, | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
expectedResult: false, | ||||||
}, | ||||||
{ | ||||||
name: "healthy and synced but operation error", | ||||||
app: v1alpha1.Application{ | ||||||
Status: v1alpha1.ApplicationStatus{ | ||||||
Health: v1alpha1.AppHealthStatus{ | ||||||
Status: health.HealthStatusHealthy, | ||||||
}, | ||||||
Sync: v1alpha1.SyncStatus{ | ||||||
Status: v1alpha1.SyncStatusCodeSynced, | ||||||
}, | ||||||
OperationState: &v1alpha1.OperationState{ | ||||||
Phase: common.OperationError, | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
expectedResult: false, | ||||||
}, | ||||||
{ | ||||||
name: "all conditions failing", | ||||||
app: v1alpha1.Application{ | ||||||
Status: v1alpha1.ApplicationStatus{ | ||||||
Health: v1alpha1.AppHealthStatus{ | ||||||
Status: health.HealthStatusDegraded, | ||||||
}, | ||||||
Sync: v1alpha1.SyncStatus{ | ||||||
Status: v1alpha1.SyncStatusCodeOutOfSync, | ||||||
}, | ||||||
OperationState: &v1alpha1.OperationState{ | ||||||
Phase: common.OperationFailed, | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
expectedResult: false, | ||||||
}, | ||||||
{ | ||||||
name: "empty health status string", | ||||||
app: v1alpha1.Application{ | ||||||
Status: v1alpha1.ApplicationStatus{ | ||||||
Health: v1alpha1.AppHealthStatus{ | ||||||
Status: "", | ||||||
}, | ||||||
Sync: v1alpha1.SyncStatus{ | ||||||
Status: v1alpha1.SyncStatusCodeSynced, | ||||||
}, | ||||||
OperationState: &v1alpha1.OperationState{ | ||||||
Phase: common.OperationSucceeded, | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
expectedResult: false, | ||||||
}, | ||||||
{ | ||||||
name: "empty sync status string", | ||||||
app: v1alpha1.Application{ | ||||||
Status: v1alpha1.ApplicationStatus{ | ||||||
Health: v1alpha1.AppHealthStatus{ | ||||||
Status: health.HealthStatusHealthy, | ||||||
}, | ||||||
Sync: v1alpha1.SyncStatus{ | ||||||
Status: "", | ||||||
}, | ||||||
OperationState: &v1alpha1.OperationState{ | ||||||
Phase: common.OperationSucceeded, | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
expectedResult: true, // empty sync status is not "OutOfSync" so it passes | ||||||
}, | ||||||
{ | ||||||
name: "completely empty application status", | ||||||
app: v1alpha1.Application{ | ||||||
Status: v1alpha1.ApplicationStatus{}, | ||||||
}, | ||||||
expectedResult: false, | ||||||
}, | ||||||
{ | ||||||
name: "no Operation state", | ||||||
app: v1alpha1.Application{ | ||||||
Status: v1alpha1.ApplicationStatus{ | ||||||
Health: v1alpha1.AppHealthStatus{ | ||||||
Status: health.HealthStatusHealthy, | ||||||
}, | ||||||
Sync: v1alpha1.SyncStatus{ | ||||||
Status: "", | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
expectedResult: true, // no OperationState defaults OperationPhaseString to "", thus passes | ||||||
}, | ||||||
} | ||||||
|
||||||
for _, tt := range tests { | ||||||
t.Run(tt.name, func(t *testing.T) { | ||||||
result := isApplicationHealthy(tt.app) | ||||||
assert.Equal(t, tt.expectedResult, result, "isApplicationHealthy() result mismatch") | ||||||
}) | ||||||
} | ||||||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit