Skip to content

Commit 7bc530d

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 f2ac936 commit 7bc530d

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
@@ -3992,14 +3992,13 @@ func Test_gateApplicableToCurrentVersion(t *testing.T) {
39923992
{
39933993
t.Run(tt.name, func(t *testing.T) {
39943994
isApplicable, err := gateApplicableToCurrentVersion(tt.gateName, tt.cv)
3995-
if err != nil && !tt.wantErr {
3996-
t.Fatalf("gateApplicableToCurrentVersion() unexpected error: %v", err)
3995+
if isApplicable != tt.expectedResult {
3996+
t.Errorf("gateApplicableToCurrentVersion() %s expected applicable %t, got applicable %t", tt.gateName, tt.expectedResult, isApplicable)
39973997
}
3998-
if err != nil {
3999-
return
4000-
}
4001-
if isApplicable && !tt.expectedResult {
4002-
t.Fatalf("gateApplicableToCurrentVersion() %s should not apply", tt.gateName)
3998+
if err != nil && !tt.wantErr {
3999+
t.Errorf("gateApplicableToCurrentVersion() unexpected error: %v", err)
4000+
} else if err == nil && tt.wantErr {
4001+
t.Error("gateApplicableToCurrentVersion() unexpected success when an error was expected")
40034002
}
40044003
})
40054004
}

0 commit comments

Comments
 (0)