Closed ns-tdemelocosta closed 3 months ago
In step 3. you are calling sqlmock.NewRows(..)
, which is using the driver.DefaultParameterConverter
and causes the panic.
Using mock.NewRows(..)
should give you the expected results: https://go.dev/play/p/7ZSsBDGeMtt
Thank you @IvoGoman . It works, I'm almost ashamed of this mistake nobody I've shown the code was able to figure out.
Description:
I'm trying to mock a database query that returns rows containing a column of type
[]string
(analogous to PostgreSQL'stext[]
field). However, even after implementing a customValueConverter
to handle the[]string
type, I'm encountering a panic when adding rows with this type usingsqlmock.NewRows(...).AddRow(...)
.Error:
Steps to Reproduce:
ValueConverter
to handle the[]string
type:func (s CustomConverter) ConvertValue(v interface{}) (driver.Value, error) { switch v.(type) { case string: return v.(string), nil case []string: return v.([]string), nil case int: return v.(int), nil default: return nil, errors.New(fmt.Sprintf("cannot convert %T with value %v", v, v)) } }
[]string
column:Expected Behavior: The mock should be able to handle rows with a
[]string
column without any issues.Actual Behavior: A panic occurs indicating that the
[]string
type is unsupported.panic: row #1, column #3 ("obfuscation_fields") type []string: unsupported type []string, a slice of string [recovered]
Additional Context:
text[]
field.ValueConverter
, but I'm still facing the issue.