Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-artie committed Mar 26, 2024
1 parent cd53515 commit a54724c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 27 deletions.
4 changes: 2 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (s *Settings) Validate() error {
return fmt.Errorf("postgres validation failed: %w", err)
}
default:
return fmt.Errorf("invalid source: %s ", s.Source)
return fmt.Errorf("invalid source: '%s'", s.Source)
}

switch s.Destination {
Expand All @@ -140,7 +140,7 @@ func (s *Settings) Validate() error {
return fmt.Errorf("kafka validation failed: %w", err)
}
default:
return fmt.Errorf("invalid destination: %s ", s.Source)
return fmt.Errorf("invalid destination: '%s'", s.Destination)
}

return nil
Expand Down
69 changes: 44 additions & 25 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,58 +7,77 @@ import (
)

func TestSettings_Validate(t *testing.T) {
dynamoCfg := &DynamoDB{
OffsetFile: "offset.txt",
AwsRegion: "us-east-1",
AwsAccessKeyID: "key-id",
AwsSecretAccessKey: "secret-access-key",
StreamArn: "arn:aws:dynamodb:us-east-1:123456789012:table/TableName/stream/2020-01-01T00:00:00.000",
TableName: "TableName",
}

type _tc struct {
name string
settings *Settings
expectErr bool
name string
settings *Settings
expectedErr string
}

tcs := []_tc{
{
name: "nil",
expectErr: true,
name: "nil",
expectedErr: "config is nil",
},
{
name: "nil kafka",
settings: &Settings{
Kafka: nil,
},
expectErr: true,
name: "nil source",
settings: &Settings{},
expectedErr: "invalid source: ''",
},
{
name: "invalid source",
settings: &Settings{Source: "foo"},
expectedErr: "invalid source: 'foo'",
},
{
name: "nil dynamodb",
settings: &Settings{
Kafka: &Kafka{
BootstrapServers: "localhost:9092",
TopicPrefix: "test",
},
Source: SourceDynamo,
DynamoDB: nil,
},
expectErr: true,
expectedErr: "dynamodb config is nil",
},
{
name: "nil destination",
settings: &Settings{Source: SourceDynamo, DynamoDB: dynamoCfg},
expectedErr: "invalid destination: ''",
},
{
name: "invalid destination",
settings: &Settings{Source: SourceDynamo, DynamoDB: dynamoCfg, Destination: "foo"},
expectedErr: "invalid destination: 'foo'",
},
{
name: "nil kafka",
settings: &Settings{Source: SourceDynamo, DynamoDB: dynamoCfg, Destination: DestinationKafka},
expectedErr: "kafka config is nil",
},
{
name: "valid",
settings: &Settings{
Source: SourceDynamo,
DynamoDB: dynamoCfg,
Destination: DestinationKafka,
Kafka: &Kafka{
BootstrapServers: "localhost:9092",
TopicPrefix: "test",
},
DynamoDB: &DynamoDB{
OffsetFile: "offset.txt",
AwsRegion: "us-east-1",
AwsAccessKeyID: "key-id",
AwsSecretAccessKey: "secret-access-key",
StreamArn: "arn:aws:dynamodb:us-east-1:123456789012:table/TableName/stream/2020-01-01T00:00:00.000",
TableName: "TableName",
},
},
},
}

for _, tc := range tcs {
err := tc.settings.Validate()
if tc.expectErr {
assert.Error(t, err, tc.name)
if tc.expectedErr != "" {
assert.ErrorContains(t, err, tc.expectedErr, tc.name)
} else {
assert.NoError(t, err, tc.name)
}
Expand Down

0 comments on commit a54724c

Please sign in to comment.