fake

package module
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: MIT Imports: 15 Imported by: 5 modules, 19 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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" comment:"Fake service image, usually can be found in our ECR with $project-fakes name"`
	ContainerName string  `toml:"container_name" comment:"Docker container name"`
	Port          int     `toml:"port" validate:"required" comment:"The port which Docker container is exposing"`
	Out           *Output `toml:"out" comment:"Fakes service config output"`
}

type Output

type Output struct {
	UseCache      bool   `toml:"use_cache" comment:"Whether to respect caching or not, if cache = true component won't be deployed again"`
	BaseURLHost   string `toml:"base_url_host" comment:"Base URL which can be used when running locally"`
	BaseURLDocker string `toml:"base_url_docker" comment:"Base URL to reach fakes service from other Docker containers"`
	// K8sService is a Kubernetes service spec used to connect locally
	K8sService *v1.Service `toml:"k8s_service" comment:"Kubernetes service spec used to connect locally"`
}

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

func NewWithContext added in v0.14.0

func NewWithContext(ctx context.Context, in *Input) (*Output, error)

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

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