Skip to content

Commit de31a3f

Browse files
committed
pkg/cvo/cvo_test: Firm up Test_gateApplicableToCurrentVersion checking
This code is from 519b466 (Bug 1978376: Add admin ack Upgradeable condition gate, 2021-07-27, #633). But I'm about to move it, and CodeRabbit complains about the unhandled "wantErr=true, but err==nil" and "expectedResult=true but isApplicable=false" situations. Extend the logic to check for those. Also move from t.Fatal* to t.Error*, because there's no harm in moving on to check the other condition, even if the first condition we check has a problem. Checking both will give the developer more information about what they need to fix to make the test happy, without them needing to retest after fixing one property before they hear about a problem with the other property. [1]: #1368 (comment)
1 parent e75b70a commit de31a3f

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

pkg/cvo/cvo_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4000,14 +4000,13 @@ func Test_gateApplicableToCurrentVersion(t *testing.T) {
40004000
{
40014001
t.Run(tt.name, func(t *testing.T) {
40024002
isApplicable, err := gateApplicableToCurrentVersion(tt.gateName, tt.cv)
4003-
if err != nil && !tt.wantErr {
4004-
t.Fatalf("gateApplicableToCurrentVersion() unexpected error: %v", err)
4003+
if isApplicable != tt.expectedResult {
4004+
t.Errorf("gateApplicableToCurrentVersion() %s expected applicable %t, got applicable %t", tt.gateName, tt.expectedResult, isApplicable)
40054005
}
4006-
if err != nil {
4007-
return
4008-
}
4009-
if isApplicable && !tt.expectedResult {
4010-
t.Fatalf("gateApplicableToCurrentVersion() %s should not apply", tt.gateName)
4006+
if err != nil && !tt.wantErr {
4007+
t.Errorf("gateApplicableToCurrentVersion() unexpected error: %v", err)
4008+
} else if err == nil && tt.wantErr {
4009+
t.Error("gateApplicableToCurrentVersion() unexpected success when an error was expected")
40114010
}
40124011
})
40134012
}

0 commit comments

Comments
 (0)