Skip to content

Commit

Permalink
Clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Oct 5, 2024
1 parent 13208da commit c8c902a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sources/postgres/adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ func valueConverterForType(dataType schema.DataType, opts *schema.Opts) (convert

return converters.NewBitConverter(opts.CharMaxLength), nil
case schema.BitVarying:
if opts == nil {
return nil, fmt.Errorf("missing options for bit varying data type")
}

return converters.NewBitVaryingConverter(opts.CharMaxLength), nil
case schema.Boolean:
return converters.BooleanPassthrough{}, nil
Expand Down
25 changes: 25 additions & 0 deletions sources/postgres/adapter/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,5 +301,30 @@ func TestValueConverterForType_Convert(t *testing.T) {
assert.Equal(t, []byte{21}, actualValue)
}
}
{
// bit varying
{
// no options
_, err := valueConverterForType(schema.BitVarying, nil)
assert.ErrorContains(t, err, "missing options for bit varying data type")
}
{
// bit varying
converter, err := valueConverterForType(schema.BitVarying, &schema.Opts{CharMaxLength: 0})
assert.NoError(t, err)

actualValue, actualErr := converter.Convert("1")
assert.NoError(t, actualErr)
assert.Equal(t, []byte{1}, actualValue)
}
{
// bit varying (5)
converter, err := valueConverterForType(schema.BitVarying, &schema.Opts{CharMaxLength: 5})
assert.NoError(t, err)

actualValue, actualErr := converter.Convert("10101")
assert.NoError(t, actualErr)
assert.Equal(t, []byte{21}, actualValue)
}
}
}

0 comments on commit c8c902a

Please sign in to comment.