ParseConfig: default_query_exec_mode: Return arg in error

If the default_query_exec_mode is unknown, the returned error
previously was:

    invalid default_query_exec_mode: <nil>

This changes it to return the argument. Add a test that unknown modes
fail to parse and include this string.
pull/1622/head
Evan Jones 2023-05-17 13:21:46 -04:00 committed by Jack Christensen
parent 11d892dfcf
commit 9de41fac75
2 changed files with 16 additions and 1 deletions

View File

@ -178,7 +178,7 @@ func ParseConfigWithOptions(connString string, options ParseConfigOptions) (*Con
case "simple_protocol":
defaultQueryExecMode = QueryExecModeSimpleProtocol
default:
return nil, fmt.Errorf("invalid default_query_exec_mode: %v", err)
return nil, fmt.Errorf("invalid default_query_exec_mode: %s", s)
}
}

View File

@ -197,6 +197,21 @@ func TestParseConfigExtractsDefaultQueryExecMode(t *testing.T) {
}
}
func TestParseConfigErrors(t *testing.T) {
t.Parallel()
for _, tt := range []struct {
connString string
expectedErrSubstring string
}{
{"default_query_exec_mode=does_not_exist", "does_not_exist"},
} {
config, err := pgx.ParseConfig(tt.connString)
require.Nil(t, config)
require.ErrorContains(t, err, tt.expectedErrSubstring)
}
}
func TestExec(t *testing.T) {
t.Parallel()