Skip to content

Commit

Permalink
Another.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Sep 20, 2024
1 parent e193d62 commit 5bc2cc2
Showing 1 changed file with 33 additions and 63 deletions.
96 changes: 33 additions & 63 deletions lib/kafkalib/partition/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,69 +7,39 @@ import (
)

func TestBigQuerySettings_Valid(t *testing.T) {
testCases := []struct {
name string
bigQuerySettings *BigQuerySettings
expectedErr string
}{
{
name: "nil",
expectedErr: "bigQuerySettings is nil",
},
{
name: "empty partitionType",
bigQuerySettings: &BigQuerySettings{},
expectedErr: "partitionTypes cannot be empty",
},
{
name: "empty partitionField",
bigQuerySettings: &BigQuerySettings{
PartitionType: "time",
},
expectedErr: "partitionField cannot be empty",
},
{
name: "empty partitionBy",
bigQuerySettings: &BigQuerySettings{
PartitionType: "time",
PartitionField: "created_at",
},
expectedErr: "partitionBy cannot be empty",
},
{
name: "invalid partitionType",
bigQuerySettings: &BigQuerySettings{
PartitionType: "invalid",
PartitionField: "created_at",
PartitionBy: "daily",
},
expectedErr: "partitionType must be one of:",
},
{
name: "invalid partitionBy",
bigQuerySettings: &BigQuerySettings{
PartitionType: "time",
PartitionField: "created_at",
PartitionBy: "invalid",
},
expectedErr: "partitionBy must be one of:",
},
{
name: "valid",
bigQuerySettings: &BigQuerySettings{
PartitionType: "time",
PartitionField: "created_at",
PartitionBy: "daily",
},
},
{
// Nil
var settings *BigQuerySettings
assert.ErrorContains(t, settings.Valid(), "bigQuerySettings is nil")
}

for _, testCase := range testCases {
actualErr := testCase.bigQuerySettings.Valid()
if testCase.expectedErr != "" {
assert.ErrorContains(t, actualErr, testCase.expectedErr, testCase.name)
} else {
assert.NoError(t, actualErr, testCase.name)
}
{
// Empty partition type
settings := &BigQuerySettings{}
assert.ErrorContains(t, settings.Valid(), "partitionTypes cannot be empty")
}
{
// Empty partition field
settings := &BigQuerySettings{PartitionType: "time"}
assert.ErrorContains(t, settings.Valid(), "partitionField cannot be empty")
}
{
// Empty partition by
settings := &BigQuerySettings{PartitionType: "time", PartitionField: "created_at"}
assert.ErrorContains(t, settings.Valid(), "partitionBy cannot be empty")
}
{
// Invalid partition type
settings := &BigQuerySettings{PartitionType: "invalid", PartitionField: "created_at", PartitionBy: "daily"}
assert.ErrorContains(t, settings.Valid(), "partitionType must be one of:")
}
{
// Invalid partition by
settings := &BigQuerySettings{PartitionType: "time", PartitionField: "created_at", PartitionBy: "invalid"}
assert.ErrorContains(t, settings.Valid(), "partitionBy must be one of:")
}
{
// Valid
settings := &BigQuerySettings{PartitionType: "time", PartitionField: "created_at", PartitionBy: "daily"}
assert.NoError(t, settings.Valid())
}
}

0 comments on commit 5bc2cc2

Please sign in to comment.