diff --git a/lib/dynamo/message_test.go b/lib/dynamo/message_test.go index c09de604..c091d6fb 100644 --- a/lib/dynamo/message_test.go +++ b/lib/dynamo/message_test.go @@ -12,38 +12,33 @@ import ( ) func TestNewMessage(t *testing.T) { - type _tc struct { + tcs := []struct { name string record *dynamodbstreams.Record tableName string - expectErr bool + expectedErr string expectedMessage *Message - } - - tcs := []_tc{ + }{ { - name: "nil record", - record: nil, - tableName: "testTable", - expectErr: true, - expectedMessage: nil, + name: "nil record", + record: nil, + tableName: "testTable", + expectedErr: "record is nil or dynamodb does not exist in this event payload", }, { - name: "nil dynamodb", - record: &dynamodbstreams.Record{}, - tableName: "testTable", - expectErr: true, - expectedMessage: nil, + name: "nil dynamodb", + record: &dynamodbstreams.Record{}, + tableName: "testTable", + expectedErr: "record is nil or dynamodb does not exist in this event payload", }, { name: "empty keys", record: &dynamodbstreams.Record{ Dynamodb: &dynamodbstreams.StreamRecord{}, }, - tableName: "testTable", - expectErr: true, - expectedMessage: nil, + tableName: "testTable", + expectedErr: "keys is nil", }, { name: "EventName INSERT", @@ -59,7 +54,6 @@ func TestNewMessage(t *testing.T) { EventName: ptr.ToString("INSERT"), }, tableName: "testTable", - expectErr: false, expectedMessage: &Message{ op: "c", tableName: "testTable", @@ -84,7 +78,6 @@ func TestNewMessage(t *testing.T) { EventName: ptr.ToString("MODIFY"), }, tableName: "testTable", - expectErr: false, expectedMessage: &Message{ op: "u", executionTime: time.Date(2023, 8, 28, 0, 0, 0, 0, time.UTC), @@ -109,7 +102,6 @@ func TestNewMessage(t *testing.T) { EventName: aws.String("REMOVE"), }, tableName: "testTable", - expectErr: false, expectedMessage: &Message{ op: "d", tableName: "testTable", @@ -132,7 +124,6 @@ func TestNewMessage(t *testing.T) { EventName: aws.String("INSERT"), }, tableName: "testTable", - expectErr: false, expectedMessage: &Message{ op: "c", tableName: "testTable", @@ -145,8 +136,8 @@ func TestNewMessage(t *testing.T) { for _, tc := range tcs { actualMessage, actualErr := NewMessage(tc.record, tc.tableName) - if tc.expectErr { - assert.Error(t, actualErr, tc.name) + if tc.expectedErr != "" { + assert.ErrorContains(t, actualErr, tc.expectedErr, tc.name) } else { assert.NoError(t, actualErr, tc.name) assert.Equal(t, tc.expectedMessage, actualMessage, tc.name) diff --git a/lib/dynamo/parse_message_test.go b/lib/dynamo/parse_message_test.go index 664ae667..0418ca2e 100644 --- a/lib/dynamo/parse_message_test.go +++ b/lib/dynamo/parse_message_test.go @@ -9,23 +9,21 @@ import ( ) func Test_NewMessageFromExport(t *testing.T) { - type _tc struct { - name string - item dynamodb.ItemResponse - keys []string - tableName string - expectedError string - } - - tcs := []_tc{ + tcs := []struct { + name string + item dynamodb.ItemResponse + keys []string + tableName string + expectedErr string + }{ { name: "Test with empty item", item: dynamodb.ItemResponse{ Item: map[string]*dynamodb.AttributeValue{}, }, - keys: []string{"id"}, - tableName: "test", - expectedError: "item is nil or keys do not exist in this item payload", + keys: []string{"id"}, + tableName: "test", + expectedErr: "item is nil or keys do not exist in this item payload", }, { name: "Test with empty keys", @@ -36,9 +34,9 @@ func Test_NewMessageFromExport(t *testing.T) { }, }, }, - keys: []string{}, - tableName: "test", - expectedError: "keys is nil", + keys: []string{}, + tableName: "test", + expectedErr: "keys is nil", }, { name: "Test with valid item and keys", @@ -56,8 +54,8 @@ func Test_NewMessageFromExport(t *testing.T) { for _, tc := range tcs { msg, err := NewMessageFromExport(tc.item, tc.keys, tc.tableName) - if tc.expectedError != "" { - assert.Equal(t, tc.expectedError, err.Error(), tc.name) + if tc.expectedErr != "" { + assert.Equal(t, tc.expectedErr, err.Error(), tc.name) } else { assert.NoError(t, err, tc.name) assert.Equal(t, tc.tableName, msg.tableName, tc.name) diff --git a/lib/postgres/parse/geom_test.go b/lib/postgres/parse/geom_test.go index 2cd5774e..b4f39a41 100644 --- a/lib/postgres/parse/geom_test.go +++ b/lib/postgres/parse/geom_test.go @@ -7,14 +7,12 @@ import ( ) func TestToPoint(t *testing.T) { - type _tc struct { + tcs := []struct { name string input string output *Point - expectError bool - } - - tcs := []_tc{ + expectedErr string + }{ { name: "Valid point", input: "(2.2945,48.8584)", @@ -23,29 +21,29 @@ func TestToPoint(t *testing.T) { { name: "Invalid format", input: "2.2945,48.8584", - expectError: true, + expectedErr: "invalid point format", }, { name: "Invalid X coordinate", input: "(abc,48.8584)", - expectError: true, + expectedErr: "invalid X coordinate", }, { name: "Invalid Y coordinate", input: "(2.2945,xyz)", - expectError: true, + expectedErr: "invalid Y coordinate:", }, { name: "Empty input", input: "", - expectError: true, + expectedErr: "invalid point format", }, } for _, tc := range tcs { point, err := ToPoint(tc.input) - if tc.expectError { - assert.Error(t, err, tc.name) + if tc.expectedErr != "" { + assert.ErrorContains(t, err, tc.expectedErr, tc.name) } else { assert.Equal(t, *tc.output, *point, tc.name) } diff --git a/lib/rdbms/primary_key/primary_keys_test.go b/lib/rdbms/primary_key/primary_keys_test.go index a3ccb344..dffbebd7 100644 --- a/lib/rdbms/primary_key/primary_keys_test.go +++ b/lib/rdbms/primary_key/primary_keys_test.go @@ -20,17 +20,15 @@ func TestNewKeys(t *testing.T) { } func TestPrimaryKeys_LoadValues(t *testing.T) { - type _tc struct { + testCases := []struct { name string startingValues []any endingValues []any keys []Key expectedKeys []Key - expectedErr bool - } - - testCases := []_tc{ + expectedErr string + }{ { name: "happy path (starting values)", keys: []Key{{Name: "id"}}, @@ -66,13 +64,12 @@ func TestPrimaryKeys_LoadValues(t *testing.T) { name: "bad data - no keys", keys: []Key{}, startingValues: []any{"123", "path:123"}, - expectedErr: true, + expectedErr: "keys (0), and passed in values (2) length does not match, keys: [], values: [123 path:123]", }, { name: "bad data - no values, so we just don't load", keys: []Key{{Name: "id"}, {Name: "content_key"}}, startingValues: []any{}, - expectedErr: false, expectedKeys: []Key{{Name: "id"}, {Name: "content_key"}}, }, } @@ -81,8 +78,8 @@ func TestPrimaryKeys_LoadValues(t *testing.T) { pk := NewKeys(testCase.keys) err := pk.LoadValues(testCase.startingValues, testCase.endingValues) - if testCase.expectedErr { - assert.Error(t, err, testCase.name) + if testCase.expectedErr != "" { + assert.ErrorContains(t, err, testCase.expectedErr, testCase.name) } else { assert.NoError(t, err, testCase.name) assert.Equal(t, testCase.expectedKeys, pk.Keys(), testCase.name) diff --git a/lib/s3lib/s3lib_test.go b/lib/s3lib/s3lib_test.go index 7ee48e59..c722646c 100644 --- a/lib/s3lib/s3lib_test.go +++ b/lib/s3lib/s3lib_test.go @@ -8,15 +8,13 @@ import ( ) func TestBucketAndPrefixFromFilePath(t *testing.T) { - type _tc struct { + tcs := []struct { name string fp string expectedBucket *string expectedPrefix *string - expectedErr bool - } - - tcs := []_tc{ + expectedErr string + }{ { name: "valid path (w/ S3 prefix)", fp: "s3://bucket/prefix", @@ -57,14 +55,14 @@ func TestBucketAndPrefixFromFilePath(t *testing.T) { { name: "invalid path", fp: "s3://bucket", - expectedErr: true, + expectedErr: "invalid S3 path, missing prefix", }, } for _, tc := range tcs { actualBucket, actualPrefix, actualErr := bucketAndPrefixFromFilePath(tc.fp) - if tc.expectedErr { - assert.Error(t, actualErr, tc.name) + if tc.expectedErr != "" { + assert.ErrorContains(t, actualErr, tc.expectedErr, tc.name) } else { assert.NoError(t, actualErr, tc.name) diff --git a/sources/postgres/adapter/adapter_test.go b/sources/postgres/adapter/adapter_test.go index f416cdfc..52c74014 100644 --- a/sources/postgres/adapter/adapter_test.go +++ b/sources/postgres/adapter/adapter_test.go @@ -191,16 +191,13 @@ func TestValueConverterForType_ToField(t *testing.T) { } func TestValueConverterForType_Convert(t *testing.T) { - type _tc struct { + tcs := []struct { name string col schema.Column value any numericValue bool expectedValue any - expectErr bool - } - - tcs := []_tc{ + }{ { name: "date (postgres.Date)", col: schema.Column{Name: "date_col", Type: schema.Date}, @@ -255,20 +252,16 @@ func TestValueConverterForType_Convert(t *testing.T) { assert.NoError(t, err, tc.name) actualValue, actualErr := converter.Convert(tc.value) - if tc.expectErr { - assert.Error(t, actualErr, tc.name) + assert.NoError(t, actualErr, tc.name) + if tc.numericValue { + bytes, ok := actualValue.([]byte) + assert.True(t, ok) + field := converter.ToField(tc.col.Name) + val, err := field.DecodeDecimal(bytes) + assert.NoError(t, err, tc.name) + assert.Equal(t, tc.expectedValue, val.String(), tc.name) } else { - assert.NoError(t, actualErr, tc.name) - if tc.numericValue { - bytes, ok := actualValue.([]byte) - assert.True(t, ok) - field := converter.ToField(tc.col.Name) - val, err := field.DecodeDecimal(bytes) - assert.NoError(t, err, tc.name) - assert.Equal(t, tc.expectedValue, val.String(), tc.name) - } else { - assert.Equal(t, tc.expectedValue, actualValue, tc.name) - } + assert.Equal(t, tc.expectedValue, actualValue, tc.name) } } }