fake

package module
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2025 License: MIT Imports: 14 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DefaultFakeServicePort = 9111
)

Variables

View Source
var (
	R = NewRecords()
)
View Source
var (
	Service *gin.Engine
)

Functions

func Func

func Func(method, path string, f func(ctx *gin.Context)) error

Func fakes method and path with a custom func

func HostDockerInternal

func HostDockerInternal() string

HostDockerInternal returns host.docker.internal that works both locally and in GHA

func JSON

func JSON(method, path string, response map[string]any, statusCode int) error

JSON fakes for method, path, response and status code

func RecordKey

func RecordKey(method, path string) string

Types

type CustomResponseWriter

type CustomResponseWriter struct {
	gin.ResponseWriter
	// contains filtered or unexported fields
}

CustomResponseWriter wraps gin.ResponseWriter to capture response data

func (*CustomResponseWriter) Write

func (w *CustomResponseWriter) Write(data []byte) (int, error)

Write captures response data

type Input

type Input struct {
	Image string  `toml:"image"`
	Port  int     `toml:"port" validate:"required"`
	Out   *Output `toml:"out"`
}

type Output

type Output struct {
	UseCache      bool   `toml:"use_cache"`
	BaseURLHost   string `toml:"base_url_host"`
	BaseURLDocker string `toml:"base_url_docker"`
}

func NewDockerFakeDataProvider

func NewDockerFakeDataProvider(in *Input) (*Output, error)

NewDockerFakeDataProvider creates new fake data provider in Docker using testcontainers-go

func NewFakeDataProvider

func NewFakeDataProvider(in *Input) (*Output, error)

NewFakeDataProvider creates new fake data provider

type Record

type Record struct {
	Method  string      `json:"method"`
	Path    string      `json:"path"`
	Headers http.Header `json:"headers"`
	ReqBody string      `json:"req_body"`
	ResBody string      `json:"res_body"`
	Status  int         `json:"status"`
}

Record is a request and response data

type Records

type Records struct {
	Data map[string][]*Record
}

func NewRecords

func NewRecords() *Records

func (*Records) Get

func (r *Records) Get(method, path string) ([]*Record, error)

Jump to

Keyboard shortcuts

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