gropanda

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 13 Imported by: 0

README

GroPanda

codecov Go Report Card License

GroPanda is a groat module for Redpanda integration testing. It simplifies the process of spinning up Redpanda containers using testcontainers-go and injecting connection details into your tests.

Installation

go get github.com/godepo/gropanda

Usage

GroPanda is designed to be used with the groat testing framework. Below is an example of how to set up a test suite with Redpanda.

Example
package mytest

import (
    "os"
    "testing"

    "github.com/godepo/groat"
    "github.com/godepo/groat/integration"
    "github.com/godepo/gropanda"
)

type (
    // Deps defines the dependencies for your tests.
    // The `groat:"redpanda"` tag tells groat to inject Redpanda settings here.
    Deps struct {
        Config *gropanda.Settings `groat:"redpanda"`
    }

    State struct {
        // Your test state here
    }

    SystemUnderTest struct {
        // Your system under test here
    }
)

var suite *integration.Container[Deps, State, *SystemUnderTest]

func TestMain(m *testing.M) {
    suite = integration.New[Deps, State, *SystemUnderTest](
        m,
        func(t *testing.T) *groat.Case[Deps, State, *SystemUnderTest] {
            return groat.New[Deps, State, *SystemUnderTest](t, func(t *testing.T, deps Deps) *SystemUnderTest {
                // Initialize your system under test using deps.Config
                return &SystemUnderTest{}
            })
        },
        gropanda.New[Deps](
            gropanda.WithInjectLabel("redpanda"),
            gropanda.WithEnableSASL,
            gropanda.WithNewServiceAccount("user", "pass"),
        ),
    )
    os.Exit(suite.Go())
}

func TestExample(t *testing.T) {
    tc := suite.Case(t)
    // Use tc.Deps.Config to interact with Redpanda
    if len(tc.Deps.Config.Brokers) == 0 {
        t.Fatal("Expected Redpanda brokers to be configured")
    }
}

Configuration

GroPanda can be configured using Option functions passed to gropanda.New:

  • WithInjectLabel(label string): Sets the tag used for dependency injection (default: "redpanda").
  • WithNameSpace(ns string): Sets a prefix for the Settings.Prefix field.
  • WithEnableSASL: Enables SASL authentication.
  • WithEnableKafkaAuthorization: Enables Kafka authorization.
  • WithNewServiceAccount(user, pass string): Adds a service account.
  • WithSuperusers(users ...string): Configures superusers.
  • WithEnableSchemaRegistryHTTPBasicAuth: Enables Basic Auth for Schema Registry.
Environment Variables

You can override some defaults using environment variables:

  • GROAT_I9N_REDPANDA_IMAGE: Override the default Redpanda Docker image.
  • GROAT_I9N_REDPANDA_BROKERS: If set, GroPanda will use these brokers instead of starting a container.
  • GROAT_I9N_REDPANDA_HTTP_PROXY_ADDRESS
  • GROAT_I9N_REDPANDA_ADMIN_PROXY_ADDRESS
  • GROAT_I9N_REDPANDA_SCHEMA_REGISTRY_ADDRESS

License

MIT

Documentation

Overview

Package gropanda provides a Redpanda integration for groat-based tests. It leverages testcontainers-go to spin up Redpanda instances for integration testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New[T any](options ...Option) integration.Bootstrap[T]

New creates a new Redpanda integration bootstrapper.

func WithEnableKafkaAuthorization

func WithEnableKafkaAuthorization(cfg *config)

WithEnableKafkaAuthorization enables Kafka authorization for the Redpanda container.

func WithEnableSASL

func WithEnableSASL(cfg *config)

WithEnableSASL enables SASL authentication for the Redpanda container.

func WithEnableSchemaRegistryHTTPBasicAuth

func WithEnableSchemaRegistryHTTPBasicAuth(c *config)

WithEnableSchemaRegistryHTTPBasicAuth enables HTTP Basic Auth for the Schema Registry.

Types

type Container

type Container[T any] struct {
	// contains filtered or unexported fields
}

Container represents a Redpanda integration container for testing. It provides Redpanda settings and manages its lifecycle during tests.

func (*Container[T]) Injector

func (c *Container[T]) Injector(t *testing.T, to T) T

Injector injects Redpanda settings into the provided target object. It also increments the fork counter and applies optional namespace prefixing.

type Option

type Option func(*config)

Option represents a configuration option for configuring the Redpanda container construction. Used to customize container behavior and specify dependency injection.

func WithInjectLabel

func WithInjectLabel(label string) Option

WithInjectLabel sets the injection label for injection settings information in dependency structure by tag. For example when label is 'redpanda':

type Deps struct {
     Config *gropanda.Settings `groat:"redpanda"`
}

func WithNameSpace

func WithNameSpace(ns string) Option

WithNameSpace sets a namespace for the Redpanda integration.

func WithNewServiceAccount

func WithNewServiceAccount(user, pass string) Option

WithNewServiceAccount adds a new service account to the Redpanda container.

func WithSuperusers

func WithSuperusers(users ...string) Option

WithSuperusers adds superusers to the Redpanda container.

type PandaContainer

type PandaContainer interface {
	// KafkaSeedBroker returns the Kafka seed broker address.
	KafkaSeedBroker(ctx context.Context) (string, error)
	// AdminAPIAddress returns the Redpanda Admin API address.
	AdminAPIAddress(ctx context.Context) (string, error)
	// SchemaRegistryAddress returns the Redpanda Schema Registry address.
	SchemaRegistryAddress(ctx context.Context) (string, error)
	// HTTPProxyAddress returns the Redpanda HTTP Proxy address.
	HTTPProxyAddress(ctx context.Context) (string, error)

	// Terminate shuts down the container.
	Terminate(ctx context.Context, opts ...testcontainers.TerminateOption) error
}

PandaContainer defines the interface for interacting with a Redpanda container.

type Settings

type Settings struct {
	// Brokers is a list of Kafka broker addresses.
	Brokers []string
	// Prefix is an optional prefix for resources created in Redpanda (e.g. topics).
	Prefix string
	// HTTPProxyAddress is the address of the Redpanda HTTP Proxy.
	HTTPProxyAddress string
	// AdminProxyAddress is the address of the Redpanda Admin API.
	AdminProxyAddress string
	// SchemaRegistryAddress is the address of the Redpanda Schema Registry.
	SchemaRegistryAddress string
}

Settings contains Redpanda connection information and configuration.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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