Skip to content

Commit

Permalink
Rename
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-artie committed Mar 30, 2024
1 parent 6c80de6 commit 24ed846
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
14 changes: 7 additions & 7 deletions lib/debezium/transformer/transformer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (m *errorIterator) Next() ([]Row, error) {
func TestDebeziumTransformer_Iteration(t *testing.T) {
{
// Empty iterator
transformer, err := NewDebeziumTransformer(mockAdatper{iter: iterator.FromSlice([][]Row{})})
transformer, err := NewDebeziumTransformer(mockAdatper{iter: iterator.ForSlice([][]Row{})})
assert.NoError(t, err)
assert.False(t, transformer.HasNext())
rows, err := transformer.Next()
Expand All @@ -81,7 +81,7 @@ func TestDebeziumTransformer_Iteration(t *testing.T) {
{
// One empty batch
batches := [][]Row{{}}
transformer, err := NewDebeziumTransformer(mockAdatper{iter: iterator.FromSlice(batches)})
transformer, err := NewDebeziumTransformer(mockAdatper{iter: iterator.ForSlice(batches)})
assert.NoError(t, err)
assert.True(t, transformer.HasNext())
rows, err := transformer.Next()
Expand All @@ -104,7 +104,7 @@ func TestDebeziumTransformer_Iteration(t *testing.T) {
}}
transformer, err := NewDebeziumTransformer(mockAdatper{
fieldConverters: fieldConverters,
iter: iterator.FromSlice(batches),
iter: iterator.ForSlice(batches),
})
assert.NoError(t, err)
// First batch
Expand Down Expand Up @@ -141,7 +141,7 @@ func TestDebeziumTransformer_Iteration(t *testing.T) {
}
transformer, err := NewDebeziumTransformer(mockAdatper{
fieldConverters: fieldConverters,
iter: iterator.FromSlice(batches),
iter: iterator.ForSlice(batches),
})
assert.NoError(t, err)
// First batch
Expand Down Expand Up @@ -217,7 +217,7 @@ func TestDebeziumTransformer_Next(t *testing.T) {
transformer, err := NewDebeziumTransformer(mockAdatper{
fieldConverters: fieldConverters,
partitionKeys: []string{"foo", "qux"},
iter: iterator.FromSlice(batches),
iter: iterator.ForSlice(batches),
},
)
assert.NoError(t, err)
Expand Down Expand Up @@ -265,7 +265,7 @@ func TestDebeziumTransformer_CreatePayload(t *testing.T) {
fieldConverters := []FieldConverter{
{Name: "qux", ValueConverter: testConverter{intField: true, returnErr: true}},
}
transformer, err := NewDebeziumTransformer(mockAdatper{fieldConverters: fieldConverters, iter: iterator.FromSlice([][]Row{})})
transformer, err := NewDebeziumTransformer(mockAdatper{fieldConverters: fieldConverters, iter: iterator.ForSlice([][]Row{})})
assert.NoError(t, err)
_, err = transformer.createPayload(Row{"qux": "quux"})
assert.ErrorContains(t, err, `failed to convert row value for key "qux": test error`)
Expand All @@ -276,7 +276,7 @@ func TestDebeziumTransformer_CreatePayload(t *testing.T) {
{Name: "foo", ValueConverter: testConverter{intField: false}},
{Name: "qux", ValueConverter: testConverter{intField: true}},
}
transformer, err := NewDebeziumTransformer(mockAdatper{fieldConverters: fieldConverters, iter: iterator.FromSlice([][]Row{})})
transformer, err := NewDebeziumTransformer(mockAdatper{fieldConverters: fieldConverters, iter: iterator.ForSlice([][]Row{})})
assert.NoError(t, err)
payload, err := transformer.createPayload(Row{"foo": "bar", "qux": "quux"})
assert.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions lib/iterator/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type sliceIterator[T any] struct {
}

// Returns an iterator that iterates over all the items in a slice.
func FromSlice[T any](items []T) Iterator[T] {
func ForSlice[T any](items []T) Iterator[T] {
return &sliceIterator[T]{items: items}
}

Expand All @@ -28,5 +28,5 @@ func (it *sliceIterator[T]) Next() (T, error) {

// Returns an iterator that emits a value once and then completes.
func Once[T any](value T) Iterator[T] {
return FromSlice([]T{value})
return ForSlice([]T{value})
}
6 changes: 3 additions & 3 deletions lib/iterator/slice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
func TestSliceIterator(t *testing.T) {
{
// No items
iter := FromSlice([][]string{})
iter := ForSlice([][]string{})
assert.False(t, iter.HasNext())
_, err := iter.Next()
assert.ErrorContains(t, err, "iterator has finished")
}
{
// One empty slice
iter := FromSlice([][]string{{}})
iter := ForSlice([][]string{{}})
assert.True(t, iter.HasNext())
item, err := iter.Next()
assert.NoError(t, err)
Expand All @@ -27,7 +27,7 @@ func TestSliceIterator(t *testing.T) {
}
{
// Two non-empty slices + one empty slice
iter := FromSlice([][]string{{"a", "b"}, {}, {"c", "d"}})
iter := ForSlice([][]string{{"a", "b"}, {}, {"c", "d"}})
assert.True(t, iter.HasNext())
{
item, err := iter.Next()
Expand Down
6 changes: 3 additions & 3 deletions lib/writer/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestWriter_Write(t *testing.T) {
// Empty iterator
destination := &mockDestination{}
writer := New(destination, false)
iter := iterator.FromSlice([][]lib.RawMessage{})
iter := iterator.ForSlice([][]lib.RawMessage{})
count, err := writer.Write(context.Background(), iter)
assert.NoError(t, err)
assert.Equal(t, 0, count)
Expand All @@ -57,7 +57,7 @@ func TestWriter_Write(t *testing.T) {
// Two empty batches
destination := &mockDestination{}
writer := New(destination, false)
iter := iterator.FromSlice([][]lib.RawMessage{{}, {}})
iter := iterator.ForSlice([][]lib.RawMessage{{}, {}})
count, err := writer.Write(context.Background(), iter)
assert.NoError(t, err)
assert.Equal(t, 0, count)
Expand All @@ -67,7 +67,7 @@ func TestWriter_Write(t *testing.T) {
// Three batches, two non-empty
destination := &mockDestination{}
writer := New(destination, false)
iter := iterator.FromSlice([][]lib.RawMessage{
iter := iterator.ForSlice([][]lib.RawMessage{
{{TopicSuffix: "a"}},
{},
{{TopicSuffix: "b"}, {TopicSuffix: "c"}},
Expand Down
4 changes: 2 additions & 2 deletions sources/postgres/adapter/transformer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestDebeziumTransformer(t *testing.T) {
{
dbzTransformer := transformer.NewDebeziumTransformerWithIterator(
PostgresAdapter{table: table},
iterator.FromSlice([][]transformer.Row{}),
iterator.ForSlice([][]transformer.Row{}),
)
assert.False(t, dbzTransformer.HasNext())
}
Expand All @@ -66,7 +66,7 @@ func TestDebeziumTransformer(t *testing.T) {
{Name: "b", ValueConverter: converters.StringPassthrough{}},
},
},
iterator.FromSlice([][]transformer.Row{
iterator.ForSlice([][]transformer.Row{
{{"a": "1", "b": "11"}, {"a": "2", "b": "12"}},
{{"a": "3", "b": "13"}, {"a": "4", "b": "14"}},
}),
Expand Down

0 comments on commit 24ed846

Please sign in to comment.