Documentation
¶
Index ¶
- func AssertAspectRatio(t *testing.T, img image.Image, expected float64)
- func AssertContains(t *testing.T, str, substr string, msg string)
- func AssertEqual(t *testing.T, expected, actual interface{}, msg string)
- func AssertError(t *testing.T, err error, msg string)
- func AssertErrorContains(t *testing.T, err error, expectedMsg string, msg string)
- func AssertFalse(t *testing.T, condition bool, msg string)
- func AssertImageDimensions(t *testing.T, img image.Image, expectedWidth, expectedHeight int)
- func AssertNil(t *testing.T, value interface{}, msg string)
- func AssertNoError(t *testing.T, err error, msg string)
- func AssertNoPanic(t *testing.T, fn func(), msg string)
- func AssertNotEqual(t *testing.T, expected, actual interface{}, msg string)
- func AssertNotNil(t *testing.T, value interface{}, msg string)
- func AssertPanics(t *testing.T, fn func(), msg string)
- func AssertTrue(t *testing.T, condition bool, msg string)
- func CopyFile(t *testing.T, src, dst string)
- func CorruptedImageBytes() []byte
- func CreateColorImage(width, height int, r, g, b uint8) *image.RGBA
- func CreateGradientImage(width, height int) *image.RGBA
- func CreateTempDir(t *testing.T) string
- func CreateTempFile(t *testing.T, content []byte) string
- func CreateTestImage(width, height int, format string) (image.Image, error)
- func CreateTestImageBytes(width, height int, format string) ([]byte, error)
- func EmptyMetadataJSON() string
- func EncodeImage(img image.Image, format string) ([]byte, error)
- func FormatTestName(parts ...interface{}) string
- func GetAspectRatio(img image.Image) float64
- func GetImageDimensions(img image.Image) (width, height int)
- func ImagesEqual(img1, img2 image.Image) bool
- func LoadTestFile(t *testing.T, filename string) []byte
- func MalformedMetadataJSON() string
- func MissingFieldsMetadataJSON() string
- func NewMockCatAPIServer(config ServerConfig) (*httptest.Server, *httptest.Server)
- func Parallel(t *testing.T)
- func PartialImageBytes() []byte
- func SkipIfShort(t *testing.T, msg string)
- func ValidGIFBytes() []byte
- func ValidJPEGBytes() []byte
- func ValidMetadataJSON() string
- func ValidMetadataJSONWithURL(url string) string
- func ValidPNGBytes() []byte
- func WriteTestFile(t *testing.T, dir, filename string, content []byte) string
- func WrongTypesMetadataJSON() string
- type ServerConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertAspectRatio ¶
AssertAspectRatio verifies the aspect ratio is within tolerance
func AssertContains ¶
AssertContains fails the test if str doesn't contain substr
func AssertEqual ¶
AssertEqual fails the test if expected != actual
func AssertError ¶
AssertError fails the test if err is nil
func AssertErrorContains ¶
AssertErrorContains fails the test if error message doesn't contain expected string
func AssertFalse ¶
AssertFalse fails the test if condition is true
func AssertImageDimensions ¶
AssertImageDimensions verifies image has expected dimensions
func AssertNoError ¶
AssertNoError fails the test if err is not nil
func AssertNoPanic ¶
AssertNoPanic fails the test if fn panics
func AssertNotEqual ¶
AssertNotEqual fails the test if expected == actual
func AssertNotNil ¶
AssertNotNil fails the test if value is nil
func AssertPanics ¶
AssertPanics fails the test if fn doesn't panic
func AssertTrue ¶
AssertTrue fails the test if condition is false
func CorruptedImageBytes ¶
func CorruptedImageBytes() []byte
CorruptedImageBytes returns invalid image data
func CreateColorImage ¶
CreateColorImage generates a solid color image
func CreateGradientImage ¶
CreateGradientImage creates an image with a horizontal gradient
func CreateTempDir ¶
CreateTempDir creates a temporary directory
func CreateTempFile ¶
CreateTempFile creates a temporary file with the given content
func CreateTestImage ¶
CreateTestImage generates a test image with specified dimensions and format
func CreateTestImageBytes ¶
CreateTestImageBytes creates image bytes for testing
func EmptyMetadataJSON ¶
func EmptyMetadataJSON() string
EmptyMetadataJSON returns empty JSON object
func EncodeImage ¶
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 ¶
GetAspectRatio calculates the aspect ratio of an image
func GetImageDimensions ¶
GetImageDimensions returns the width and height of an image
func ImagesEqual ¶
ImagesEqual compares two images for equality
func LoadTestFile ¶
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 PartialImageBytes ¶
func PartialImageBytes() []byte
PartialImageBytes returns truncated JPEG data
func SkipIfShort ¶
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 ¶
ValidMetadataJSONWithURL returns valid metadata with a specific URL
func ValidPNGBytes ¶
func ValidPNGBytes() []byte
ValidPNGBytes returns minimal valid PNG image bytes
func WriteTestFile ¶
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