aboutsummaryrefslogtreecommitdiff
path: root/test/kafka/internal/testutil/docker.go
blob: e839fe28c7bec8c1da464708208d8ea07e8259e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package testutil

import (
	"os"
	"testing"
)

// DockerEnvironment provides utilities for Docker-based integration tests
type DockerEnvironment struct {
	KafkaBootstrap string
	KafkaGateway   string
	SchemaRegistry string
	Available      bool
}

// NewDockerEnvironment creates a new Docker environment helper
func NewDockerEnvironment(t *testing.T) *DockerEnvironment {
	t.Helper()

	env := &DockerEnvironment{
		KafkaBootstrap: os.Getenv("KAFKA_BOOTSTRAP_SERVERS"),
		KafkaGateway:   os.Getenv("KAFKA_GATEWAY_URL"),
		SchemaRegistry: os.Getenv("SCHEMA_REGISTRY_URL"),
	}

	env.Available = env.KafkaBootstrap != ""

	if env.Available {
		t.Logf("Docker environment detected:")
		t.Logf("  Kafka Bootstrap: %s", env.KafkaBootstrap)
		t.Logf("  Kafka Gateway: %s", env.KafkaGateway)
		t.Logf("  Schema Registry: %s", env.SchemaRegistry)
	}

	return env
}

// SkipIfNotAvailable skips the test if Docker environment is not available
func (d *DockerEnvironment) SkipIfNotAvailable(t *testing.T) {
	t.Helper()
	if !d.Available {
		t.Skip("Skipping Docker integration test - set KAFKA_BOOTSTRAP_SERVERS to run")
	}
}

// RequireKafka ensures Kafka is available or skips the test
func (d *DockerEnvironment) RequireKafka(t *testing.T) {
	t.Helper()
	if d.KafkaBootstrap == "" {
		t.Skip("Kafka bootstrap servers not available")
	}
}

// RequireGateway ensures Kafka Gateway is available or skips the test
func (d *DockerEnvironment) RequireGateway(t *testing.T) {
	t.Helper()
	if d.KafkaGateway == "" {
		t.Skip("Kafka Gateway not available")
	}
}

// RequireSchemaRegistry ensures Schema Registry is available or skips the test
func (d *DockerEnvironment) RequireSchemaRegistry(t *testing.T) {
	t.Helper()
	if d.SchemaRegistry == "" {
		t.Skip("Schema Registry not available")
	}
}