diff --git a/lib/kafkalib/partition/settings_test.go b/lib/kafkalib/partition/settings_test.go index 75ea7f039..209af8eb3 100644 --- a/lib/kafkalib/partition/settings_test.go +++ b/lib/kafkalib/partition/settings_test.go @@ -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()) } }