Postgres: Improve invalid port specifier error during health check (#105536)

normalize error message in postgres invalid port specifier error
This commit is contained in:
Sriram
2025-05-16 11:51:12 +01:00
committed by GitHub
parent 778563223b
commit fcb1e9c9e5
4 changed files with 26 additions and 3 deletions

View File

@ -2,6 +2,7 @@ package sqleng
import (
"errors"
"fmt"
"net"
"testing"
@ -48,6 +49,15 @@ func TestErrToHealthCheckResult(t *testing.T) {
JSONDetails: []byte(`{"errorDetailsLink":"https://grafana.com/docs/grafana/latest/datasources/postgres","verboseMessage":"internal server error"}`),
},
},
{
name: "invalid port specifier error",
err: fmt.Errorf("%w %q: %w", ErrInvalidPortSpecified, `"foo.bar.co"`, errors.New(`strconv.Atoi: parsing "foo.bar.co": invalid syntax`)),
want: &backend.CheckHealthResult{
Status: backend.HealthStatusError,
Message: "Connection string error: invalid port in host specifier",
JSONDetails: []byte(`{"errorDetailsLink":"https://grafana.com/docs/grafana/latest/datasources/postgres","verboseMessage":"invalid port in host specifier \"\\\"foo.bar.co\\\"\": strconv.Atoi: parsing \"foo.bar.co\": invalid syntax"}`),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {