package testutil

import "git.sr.ht/~jamesponddotco/bunnystorage-go/internal/testutil"

Package testutil provides utilities for testing.

Index

Constants

const (
	// ErrMissingEnvVar is returned when an environment variable is missing.
	ErrMissingEnvVar xerrors.Error = "missing environment variable"

	// ErrTestClient is returned when the test client fails to initialize.
	ErrTestClient xerrors.Error = "failed to initialize test client"
)
const MockServerAddr string = "localhost:62769"

MockServerAddr is the address of the mock server.

Functions

func ReadFile

func ReadFile(t *testing.T, name string) (file []byte)

ReadFile reads the named file and either returns its contents or fails the test.

func SetupClient

func SetupClient() (client *bunnystorage.Client, err error)

SetupClient sets up a test client for integration tests.

The following environment variables are required: - BUNNY_STORAGE_ZONE - BUNNY_READ_API_KEY - BUNNY_WRITE_API_KEY

The test will fail if any of them are empty or not set.

func SetupFile

func SetupFile(t *testing.T) (name string, size int64, err error)

SetupFile sets up a simple text file for use in integration tests.

func SetupMockClient

func SetupMockClient(t *testing.T) *bunnystorage.Client

SetupMockClient sets up a mock client for mocking tests.

func SetupMockServer

func SetupMockServer(t *testing.T) (mux *http.ServeMux, teardown func())

SetupMockServer sets up a mock server for mocking tests.

Source Files

setup.go testutil.go

Version
v0.3.0 (latest)
Published
Jul 11, 2023
Platform
linux/amd64
Imports
8 packages
Last checked
1 day ago

Tools for package owners.