Skip to content

Commit

Permalink
chore: use test function pattern even more
Browse files Browse the repository at this point in the history
  • Loading branch information
mdelapenya committed Nov 21, 2024
1 parent 01ba4e9 commit 63ee6cf
Showing 1 changed file with 72 additions and 80 deletions.
152 changes: 72 additions & 80 deletions modules/kafka/kafka_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,95 +259,87 @@ func TestKafka_restProxyService(t *testing.T) {
}

func TestKafka_listenersValidation(t *testing.T) {
ctx := context.Background()
runWithErrorFn := func(t *testing.T, listeners []kafka.KafkaListener) {
t.Helper()

c, err := kafka.Run(context.Background(),
"confluentinc/confluent-local:7.6.1",
kafka.WithClusterID("test-cluster"),
kafka.WithListener(listeners),
)
require.Error(t, err)
require.Nil(t, c, "expected container to be nil")
}

testCases := []struct {
name string
listeners []kafka.KafkaListener
}{
{
name: "reserved listener port duplication 1",
listeners: []kafka.KafkaListener{
{
Name: "BROKER",
Host: "kafka",
Port: "9093",
},
t.Run("reserved-listener/port-9093", func(t *testing.T) {
runWithErrorFn(t, []kafka.KafkaListener{
{
Name: "BROKER",
Host: "kafka",
Port: "9093",
},
},
{
name: "reserved listener port duplication 2",
listeners: []kafka.KafkaListener{
{
Name: "BROKER",
Host: "kafka",
Port: "9094",
},
})
})

t.Run("reserved-listener/port-9094", func(t *testing.T) {
runWithErrorFn(t, []kafka.KafkaListener{
{
Name: "BROKER",
Host: "kafka",
Port: "9094",
},
},
{
name: "reserved listener name duplication (controller)",
listeners: []kafka.KafkaListener{
{
Name: " cOnTrOller ",
Host: "kafka",
Port: "9092",
},
})
})

t.Run("reserved-listener/controller-duplicated", func(t *testing.T) {
runWithErrorFn(t, []kafka.KafkaListener{
{
Name: " cOnTrOller ",
Host: "kafka",
Port: "9092",
},
},
{
name: "reserved listener name duplication (plaintext)",
listeners: []kafka.KafkaListener{
{
Name: "plaintext",
Host: "kafka",
Port: "9092",
},
})
})

t.Run("reserved-listener/plaintext-duplicated", func(t *testing.T) {
runWithErrorFn(t, []kafka.KafkaListener{
{
Name: "plaintext",
Host: "kafka",
Port: "9092",
},
},
{
name: "duplicated ports not allowed",
listeners: []kafka.KafkaListener{
{
Name: "test",
Host: "kafka",
Port: "9092",
},
{
Name: "test2",
Host: "kafka",
Port: "9092",
},
})
})

t.Run("duplicated-ports", func(t *testing.T) {
runWithErrorFn(t, []kafka.KafkaListener{
{
Name: "test",
Host: "kafka",
Port: "9092",
},
},
{
name: "duplicated names not allowed",
listeners: []kafka.KafkaListener{
{
Name: "test",
Host: "kafka",
Port: "9092",
},
{
Name: "test",
Host: "kafka",
Port: "9095",
},
{
Name: "test2",
Host: "kafka",
Port: "9092",
},
},
}
})
})

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
c, err := kafka.Run(ctx,
"confluentinc/confluent-local:7.6.1",
kafka.WithClusterID("test-cluster"),
kafka.WithListener(tc.listeners),
)
require.Error(t, err)
require.Nil(t, c, "expected container to be nil")
t.Run("duplicated-names", func(t *testing.T) {
runWithErrorFn(t, []kafka.KafkaListener{
{
Name: "test",
Host: "kafka",
Port: "9092",
},
{
Name: "test",
Host: "kafka",
Port: "9095",
},
})
}
})
}

func createTopics(brokers []string, topics []string) error {

Check failure on line 345 in modules/kafka/kafka_test.go

View workflow job for this annotation

GitHub Actions / test-modules (1.22.x, ubuntu-latest, kafka) / modules/kafka/ubuntu-latest/1.22.x

func `createTopics` is unused (unused)

Check failure on line 345 in modules/kafka/kafka_test.go

View workflow job for this annotation

GitHub Actions / test-modules (1.x, ubuntu-latest, kafka) / modules/kafka/ubuntu-latest/1.x

func `createTopics` is unused (unused)
Expand Down

0 comments on commit 63ee6cf

Please sign in to comment.