testutils

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package testutils provides common utilities for testing across the project.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertErrorContains

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

AssertErrorContains checks if the error message contains the expected text.

func CreateMockJSONResponse

func CreateMockJSONResponse(t *testing.T, statusCode int, body interface{}) *http.Response

CreateMockJSONResponse creates a mock HTTP response with JSON content.

func CreateTempFile

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

CreateTempFile creates a temporary file with the given content and returns its path. The caller is responsible for cleaning up the file.

func GetProjectRoot

func GetProjectRoot() (string, error)

GetProjectRoot returns the absolute path to the project root.

func LoadTestFile

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

LoadTestFile reads and returns the content of a test file.

func RunTestCases

func RunTestCases(t *testing.T, testCases []TestCase)

RunTestCases runs a set of test cases with proper setup and teardown.

func SetupMockServer

func SetupMockServer(t *testing.T, configs []MockServerConfig) (*httptest.Server, string)

SetupMockServer creates a test HTTP server with the given configuration. Returns the server instance and its base URL.

func SkipIfNotIntegration

func SkipIfNotIntegration(t *testing.T)

SkipIfNotIntegration skips the test if the -integration flag is not set.

func SkipIfShort

func SkipIfShort(t *testing.T)

SkipIfShort skips the test if the -short flag is set.

Types

type MockServerConfig

type MockServerConfig struct {
	Method       string
	Path         string
	Status       int
	ResponseBody interface{}
	Headers      map[string]string
}

MockServerConfig holds configuration for a mock HTTP server.

type TestCase

type TestCase struct {
	Name     string
	TestFunc func(t *testing.T)
}

TestCase represents a test case with a name and test function.

Jump to

Keyboard shortcuts

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