resend

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: MIT Imports: 11 Imported by: 0

README

testcontainers-go-resend

A Testcontainers for Go module that provides a mock Resend API for integration testing.

It uses Microcks under the hood to serve mock responses based on the official Resend OpenAPI spec.

Install

go get github.com/mdelapenya/testcontainers-go-resend

Usage

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/testcontainers/testcontainers-go"

	"github.com/mdelapenya/testcontainers-go-resend"
)

func main() {
	ctx := context.Background()

	ctr, err := resend.Run(ctx, resend.DefaultImage)
	defer func() {
		if err := testcontainers.TerminateContainer(ctr); err != nil {
			log.Printf("failed to terminate container: %s", err)
		}
	}()
	if err != nil {
		log.Fatal(err)
	}

	baseURL, err := ctr.BaseURL(ctx)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("Resend mock API available at:", baseURL)
}

Custom OpenAPI spec URL

By default the module fetches the latest Resend OpenAPI spec from GitHub. If the download fails, it falls back to an embedded copy.

You can point to a different spec URL:

ctr, err := resend.Run(ctx, resend.DefaultImage,
	resend.WithSpecURL("https://example.com/my-resend-spec.yaml"),
)

Supported endpoints

The mock covers all Resend API resources: emails, domains, API keys, templates, audiences, contacts, broadcasts, webhooks, segments, topics, contact properties, contact segments, and contact topics.

License

MIT

Documentation

Index

Examples

Constants

View Source
const (
	// DefaultImage is the default Microcks image used to mock the Resend API.
	DefaultImage = "quay.io/microcks/microcks-uber:1.12.0"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Container

type Container struct {
	*microcks.MicrocksContainer
	// contains filtered or unexported fields
}

Container wraps a MicrocksContainer pre-loaded with the Resend OpenAPI spec.

func Run

Run creates an instance of the Container type, starting a Microcks container pre-loaded with the Resend OpenAPI spec.

Example
// runContainer {
ctx := context.Background()

ctr, err := resend.Run(ctx, resend.DefaultImage)
defer func() {
	if err := testcontainers.TerminateContainer(ctr); err != nil {
		log.Printf("failed to terminate container: %s", err)
	}
}()
if err != nil {
	log.Printf("failed to start container: %s", err)
	return
}
// }

state, err := ctr.State(ctx)
if err != nil {
	log.Printf("failed to get container state: %s", err)
	return
}

fmt.Println(state.Running)
Output:
true

func (*Container) BaseURL

func (c *Container) BaseURL(ctx context.Context) (string, error)

BaseURL returns the mock endpoint base URL for the Resend REST API. This is the URL you should configure as the Resend API base URL in your client.

Example
ctx := context.Background()

ctr, err := resend.Run(ctx, resend.DefaultImage)
defer func() {
	if err := testcontainers.TerminateContainer(ctr); err != nil {
		log.Printf("failed to terminate container: %s", err)
	}
}()
if err != nil {
	log.Printf("failed to start container: %s", err)
	return
}

// baseURL {
baseURL, err := ctr.BaseURL(ctx)
// }
if err != nil {
	log.Printf("failed to get base URL: %s", err)
	return
}

fmt.Println(baseURL != "")
Output:
true

func (*Container) ServiceName

func (c *Container) ServiceName() string

ServiceName returns the API service name extracted from the OpenAPI spec (e.g. "Resend").

func (*Container) ServiceVersion

func (c *Container) ServiceVersion() string

ServiceVersion returns the API service version extracted from the OpenAPI spec (e.g. "1.5.0").

type Option

type Option func(*resendOptions) error

Option is a function that configures the Resend module.

func WithSpecURL

func WithSpecURL(url string) Option

WithSpecURL sets a custom URL to fetch the Resend OpenAPI spec from. If the URL is unreachable, the module falls back to the embedded spec.

func (Option) Customize

Customize is a NOOP. It's defined to satisfy the testcontainers.ContainerCustomizer interface.

Jump to

Keyboard shortcuts

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