Skip to content

Commit c6debe2

Browse files
committed
Assert on typed x509 error first before macOS-specific fallback
Only falls back to macOS-specific x509 error assertion if the initial typed assertion failed. Fixes test failure when running with Go 1.20, 1.19.5 or 1.18.10 due to golang/go#56891
1 parent 4f85ac8 commit c6debe2

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

rest/config_test.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2604,12 +2604,16 @@ func TestCollectionsValidation(t *testing.T) {
26042604
// We get OS specific errors on x509.UnknownAuthorityError so we switch the expected error string if on darwin OS
26052605
func requireErrorWithX509UnknownAuthority(t testing.TB, actual, expected error) {
26062606
expectedErrorString := expected.Error()
2607-
switch errorType := expected.(type) {
2608-
case x509.UnknownAuthorityError:
2609-
expectedErrorString = errorType.Error()
2610-
if runtime.GOOS == "darwin" {
2611-
expectedErrorString = "certificate is not trusted"
2612-
}
2607+
if strings.Contains(actual.Error(), expectedErrorString) {
2608+
return
2609+
}
2610+
2611+
// workaround for versions of go affected by https://github.com/golang/go/issues/56891
2612+
isMacOS := runtime.GOOS == "darwin"
2613+
_, isX509Error := expected.(x509.UnknownAuthorityError)
2614+
if isX509Error && isMacOS {
2615+
expectedErrorString = "certificate is not trusted"
26132616
}
2617+
26142618
require.ErrorContains(t, actual, expectedErrorString)
26152619
}

0 commit comments

Comments
 (0)