Skip to content

Commit

Permalink
Refactoring BitConverter + Adding tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Oct 3, 2024
1 parent 3aa5d40 commit 3dd56c4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/debezium/converters/bit.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,18 @@ type BitConverter struct {
charMaxLength int
}

func (BitConverter) ToField(name string) debezium.Field {
return debezium.Field{
FieldName: name,
Type: debezium.Boolean,
func (b BitConverter) ToField(name string) debezium.Field {
switch b.charMaxLength {
case 1:
return debezium.Field{
FieldName: name,
Type: debezium.Boolean,
}
default:
return debezium.Field{
FieldName: name,
Type: debezium.String,
}
}
}

Expand Down
21 changes: 21 additions & 0 deletions lib/debezium/converters/bit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@ import (
"testing"
)

func TestBitConverter_ToField(t *testing.T) {
{
// char size not specified
field := NewBitConverter(0).ToField("foo")
assert.Equal(t, "foo", field.FieldName)
assert.Equal(t, "string", string(field.Type))
}
{
// char max size 1
field := NewBitConverter(1).ToField("foo")
assert.Equal(t, "foo", field.FieldName)
assert.Equal(t, "boolean", string(field.Type))
}
{
// char max size 5
field := NewBitConverter(5).ToField("foo")
assert.Equal(t, "foo", field.FieldName)
assert.Equal(t, "string", string(field.Type))
}
}

func TestBitConverter_Convert(t *testing.T) {
{
// char size not specified
Expand Down

0 comments on commit 3dd56c4

Please sign in to comment.