testutil

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertAspectRatio

func AssertAspectRatio(t *testing.T, img image.Image, expected float64)

AssertAspectRatio verifies the aspect ratio is within tolerance

func AssertContains

func AssertContains(t *testing.T, str, substr string, msg string)

AssertContains fails the test if str doesn't contain substr

func AssertEqual

func AssertEqual(t *testing.T, expected, actual interface{}, msg string)

AssertEqual fails the test if expected != actual

func AssertError

func AssertError(t *testing.T, err error, msg string)

AssertError fails the test if err is nil

func AssertErrorContains

func AssertErrorContains(t *testing.T, err error, expectedMsg string, msg string)

AssertErrorContains fails the test if error message doesn't contain expected string

func AssertFalse

func AssertFalse(t *testing.T, condition bool, msg string)

AssertFalse fails the test if condition is true

func AssertImageDimensions

func AssertImageDimensions(t *testing.T, img image.Image, expectedWidth, expectedHeight int)

AssertImageDimensions verifies image has expected dimensions

func AssertNil

func AssertNil(t *testing.T, value interface{}, msg string)

AssertNil fails the test if value is not nil

func AssertNoError

func AssertNoError(t *testing.T, err error, msg string)

AssertNoError fails the test if err is not nil

func AssertNoPanic

func AssertNoPanic(t *testing.T, fn func(), msg string)

AssertNoPanic fails the test if fn panics

func AssertNotEqual

func AssertNotEqual(t *testing.T, expected, actual interface{}, msg string)

AssertNotEqual fails the test if expected == actual

func AssertNotNil

func AssertNotNil(t *testing.T, value interface{}, msg string)

AssertNotNil fails the test if value is nil

func AssertPanics

func AssertPanics(t *testing.T, fn func(), msg string)

AssertPanics fails the test if fn doesn't panic

func AssertTrue

func AssertTrue(t *testing.T, condition bool, msg string)

AssertTrue fails the test if condition is false

func CopyFile

func CopyFile(t *testing.T, src, dst string)

CopyFile copies a file from src to dst

func CorruptedImageBytes

func CorruptedImageBytes() []byte

CorruptedImageBytes returns invalid image data

func CreateColorImage

func CreateColorImage(width, height int, r, g, b uint8) *image.RGBA

CreateColorImage generates a solid color image

func CreateGradientImage

func CreateGradientImage(width, height int) *image.RGBA

CreateGradientImage creates an image with a horizontal gradient

func CreateTempDir

func CreateTempDir(t *testing.T) string

CreateTempDir creates a temporary directory

func CreateTempFile

func CreateTempFile(t *testing.T, content []byte) string

CreateTempFile creates a temporary file with the given content

func CreateTestImage

func CreateTestImage(width, height int, format string) (image.Image, error)

CreateTestImage generates a test image with specified dimensions and format

func CreateTestImageBytes

func CreateTestImageBytes(width, height int, format string) ([]byte, error)

CreateTestImageBytes creates image bytes for testing

func EmptyMetadataJSON

func EmptyMetadataJSON() string

EmptyMetadataJSON returns empty JSON object

func EncodeImage

func EncodeImage(img image.Image, format string) ([]byte, error)

EncodeImage encodes an image to bytes in the specified format

func FormatTestName

func FormatTestName(parts ...interface{}) string

FormatTestName formats a test name for table-driven tests

func GetAspectRatio

func GetAspectRatio(img image.Image) float64

GetAspectRatio calculates the aspect ratio of an image

func GetImageDimensions

func GetImageDimensions(img image.Image) (width, height int)

GetImageDimensions returns the width and height of an image

func ImagesEqual

func ImagesEqual(img1, img2 image.Image) bool

ImagesEqual compares two images for equality

func LoadTestFile

func LoadTestFile(t *testing.T, filename string) []byte

LoadTestFile loads a file from the testdata directory

func MalformedMetadataJSON

func MalformedMetadataJSON() string

MalformedMetadataJSON returns JSON with syntax errors

func MissingFieldsMetadataJSON

func MissingFieldsMetadataJSON() string

MissingFieldsMetadataJSON returns JSON with missing required fields

func NewMockCatAPIServer

func NewMockCatAPIServer(config ServerConfig) (*httptest.Server, *httptest.Server)

NewMockCatAPIServer creates a test HTTP server that simulates the cat API Returns metadata server URL and image server URL

func Parallel

func Parallel(t *testing.T)

Parallel marks the test as capable of running in parallel

func PartialImageBytes

func PartialImageBytes() []byte

PartialImageBytes returns truncated JPEG data

func SkipIfShort

func SkipIfShort(t *testing.T, msg string)

SkipIfShort skips the test if running in short mode

func ValidGIFBytes

func ValidGIFBytes() []byte

ValidGIFBytes returns minimal valid GIF image bytes

func ValidJPEGBytes

func ValidJPEGBytes() []byte

ValidJPEGBytes returns minimal valid JPEG image bytes

func ValidMetadataJSON

func ValidMetadataJSON() string

ValidMetadataJSON returns a valid CatMetadata JSON string Use %s placeholder for URL that will be replaced with image server URL

func ValidMetadataJSONWithURL

func ValidMetadataJSONWithURL(url string) string

ValidMetadataJSONWithURL returns valid metadata with a specific URL

func ValidPNGBytes

func ValidPNGBytes() []byte

ValidPNGBytes returns minimal valid PNG image bytes

func WriteTestFile

func WriteTestFile(t *testing.T, dir, filename string, content []byte) string

WriteTestFile writes content to a file in the given directory

func WrongTypesMetadataJSON

func WrongTypesMetadataJSON() string

WrongTypesMetadataJSON returns JSON with incorrect field types

Types

type ServerConfig

type ServerConfig struct {
	MetadataResponse   string        // JSON to return for metadata
	ImageData          []byte        // Image bytes to return
	MetadataDelay      time.Duration // Artificial delay for metadata
	ImageDelay         time.Duration // Artificial delay for image
	MetadataStatus     int           // HTTP status for metadata
	ImageStatus        int           // HTTP status for image
	ShouldFailMetadata bool          // Simulate metadata fetch failure
	ShouldFailImage    bool          // Simulate image fetch failure
}

ServerConfig configures the behavior of the mock HTTP server

Jump to

Keyboard shortcuts

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