stack

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TestKafkaAlias is both the network alias and the container hostname. The
	// two must match: the broker advertises its own hostname on the internal
	// listener, so peers only resolve it if that hostname is DNS-resolvable on
	// the test network.
	TestKafkaAlias = "kafka"
	// TestKafkaInternalPort is the BROKER listener, reachable container-to-container.
	// The host-facing PLAINTEXT listener (9093) is owned by the module.
	TestKafkaInternalPort = "9092"
	// TestKafkaImage must be a KRaft-capable confluent-local image (>= 7.4.0).
	// The module's starter script sources /etc/confluent/docker/bash-config, so
	// apache/kafka images will not work here.
	TestKafkaImage = "confluentinc/confluent-local:7.5.0"
)
View Source
const (
	TestNetworkAlias = "checkout-app"
	TestDbName       = "checkout"
	TestUsername     = "checkout"
	TestDBPassword   = "not-a-real-db-passwd"
	TestAuthPassword = "not-a-real-auth-passwd"
	TestHTTPPort     = "8000/tcp" // matches cmd.DefaultServerPort
	TestPostgresPort = "5432/tcp"
)

Variables

This section is empty.

Functions

func CreateNetwork

func CreateNetwork(t *testing.T, ctx context.Context) *testcontainers.DockerNetwork

Create a Docker network for the integration test

func MakeAuthClient

func MakeAuthClient(t *testing.T, baseURL, password string) *client.Client

func MakeRandomizedTestItem

func MakeRandomizedTestItem(id int) *model.Item

Types

type KafkaContainer

type KafkaContainer struct {
	// contains filtered or unexported fields
}

func StartKafka

func StartKafka(t *testing.T,
	ctx context.Context,
	netName string,
	withLogger bool,
) *KafkaContainer

StartKafka runs a single-node KRaft broker attached to netName.

func (*KafkaContainer) Broker

func (k *KafkaContainer) Broker() string

Broker returns the first host-reachable bootstrap address.

func (*KafkaContainer) Brokers

func (k *KafkaContainer) Brokers() []string

Brokers returns host-reachable bootstrap addresses, for clients constructed inside the test process.

func (*KafkaContainer) CreateTopics

func (k *KafkaContainer) CreateTopics(t *testing.T, ctx context.Context, partitions int32, topics ...string)

CreateTopics provisions topics up front so tests do not race broker-side auto creation. Producing to a missing topic fails with UNKNOWN_TOPIC_OR_PARTITION unless the client opts in via kgo.AllowAutoTopicCreation, and even then the first attempt races the metadata refresh. Already-existing topics are ignored.

Prefer partitions > 1. A single-partition topic orders every record globally, which makes a test pass regardless of whether the producer sets a partition key — exactly the bug such a test should be catching.

func (*KafkaContainer) InternalBroker

func (k *KafkaContainer) InternalBroker() string

InternalBroker returns the in-network bootstrap address, for clients running in sibling containers on the same network.

type Opts

type Opts struct {
	// DB
	DbLogs bool
	// Checkout App
	AppLogs bool
	Debug   bool

	// EnableEvents starts kafka and a notifier alongside orders, wiring orders
	// to publish and the notifier to consume.
	EnableEvents bool
}

type PGContainer

type PGContainer struct {
	// contains filtered or unexported fields
}

func StartPostgres

func StartPostgres(t *testing.T,
	ctx context.Context,
	netName string,
	withLogger bool,
) *PGContainer

type Stack

type Stack struct {
	// contains filtered or unexported fields
}

func MakeStack

func MakeStack(t *testing.T, ctx context.Context, opts *Opts) *Stack

func (*Stack) AppURL

func (s *Stack) AppURL() string

func (Stack) AuthPsswd

func (s Stack) AuthPsswd() string

func (*Stack) NotifierURL

func (s *Stack) NotifierURL() string

NotifierURL returns the notifier's base URL. Only valid when the stack was built with EnableEvents.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL