testdump

package
v0.0.0-...-b14404a Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: BSD-3-Clause Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrHeaderNotFound = errors.New("testdump: HTTP header not found")
View Source
var ErrMetadataNotFound = errors.New("testdump: gRPC metadata not found")

Functions

func GRPC

func GRPC(rw readerWriter, dump *GRPCDump, opt *GRPCOption, hooks ...Hook[*GRPCDump]) error

func HTTP

func HTTP(rw readerWriter, dump *HTTPDump, opt *HTTPOption, hooks ...HTTPHook) error

func HTTPFile

func HTTPFile(w *http.Response, r *http.Request) readerWriter

HTTPFile returns a filename based on the http request method and response status code.

func JSON

func JSON[T any](rw readerWriter, t T, opt *JSONOption) error

NOTE: Why using a type is bad - because if we serialize to structs, the keys that are removed won't be compared. Ideally, using map[string]any or just any should work better for snapshot testing.

func MarshalGRPC

func MarshalGRPC(d *GRPCDump) ([]byte, error)

func MarshalHTTP

func MarshalHTTP(d *HTTPDump) ([]byte, error)

func MarshalJSON

func MarshalJSON[T any](t T) ([]byte, error)

func MarshalMySQL

func MarshalMySQL(s *SQL) ([]byte, error)

func MarshalPostgres

func MarshalPostgres(s *SQL) ([]byte, error)

func MarshalYAML

func MarshalYAML[T any](t T) ([]byte, error)

func MySQL

func MySQL(rw readerWriter, sql *SQL, opt *MySQLOption, hooks ...Hook[*SQL]) error

func Postgres

func Postgres(rw readerWriter, sql *SQL, opt *PostgresOption, hooks ...Hook[*SQL]) error

func Snapshot

func Snapshot[T any](rw readerWriter, t T, s S[T]) error

func Text

func Text(rw readerWriter, received string) error

func UnmarshalJSON

func UnmarshalJSON[T any](b []byte) (T, error)

The problem is here - the unmarshalling actually causes a loss of data.

func UnmarshalYAML

func UnmarshalYAML[T any](b []byte) (T, error)

func YAML

func YAML[T any](rw readerWriter, t T, opt *YAMLOption) error

Types

type CUEOption

type CUEOption struct {
	Schema     string       // The raw schema.
	SchemaPath string       // Path to the cue file.
	Options    []cue.Option // List of options
}

func (*CUEOption) Validate

func (o *CUEOption) Validate(data []byte) error

type CompareAnyFunc

type CompareAnyFunc (func(a, b any) error)

func (CompareAnyFunc) CompareAny

func (f CompareAnyFunc) CompareAny(a, b any) error

type CompareFunc

type CompareFunc[T any] (func(a, b T) error)

func (CompareFunc[T]) Compare

func (f CompareFunc[T]) Compare(a, b T) error

type DiffError

type DiffError = internal.DiffError

func AsDiffError

func AsDiffError(err error) (*DiffError, bool)

type File

type File struct {
	Name string
}

func NewFile

func NewFile(name string) *File

func (*File) Read

func (rw *File) Read() ([]byte, error)

func (*File) Write

func (rw *File) Write(b []byte) error

type GRPCComparer

type GRPCComparer struct {
	Message  []cmp.Option
	Metadata []cmp.Option
}

func (GRPCComparer) Compare

func (c GRPCComparer) Compare(snapshot, received *GRPCDump) error

type GRPCDump

type GRPCDump = grpcdump.Dump

func UnmarshalGRPC

func UnmarshalGRPC(b []byte) (*GRPCDump, error)

type GRPCOption

type GRPCOption struct {
	Message  []cmp.Option
	Metadata []cmp.Option
}

type HTTPComparer

type HTTPComparer struct {
	Header  []cmp.Option
	Body    []cmp.Option
	Trailer []cmp.Option
}

func (HTTPComparer) Compare

func (c HTTPComparer) Compare(snapshot, received *HTTPDump) error

type HTTPDump

type HTTPDump struct {
	W *http.Response
	R *http.Request
}

func UnmarshalHTTP

func UnmarshalHTTP(b []byte) (*HTTPDump, error)

type HTTPHook

type HTTPHook = Hook[*HTTPDump]

type HTTPOption

type HTTPOption struct {
	Header  []cmp.Option
	Body    []cmp.Option
	Trailer []cmp.Option
}

type Hook

type Hook[T any] func(S[T]) S[T]

func CompareHook

func CompareHook[T any](hook func(snapshot T, received T) error) Hook[T]

func Copier

func Copier[T any]() Hook[T]

func MarshalHook

func MarshalHook[T any](hook func(T) (T, error)) Hook[T]

func MaskMessage

func MaskMessage(fields ...string) Hook[*GRPCDump]

func MaskMetadata

func MaskMetadata(headers ...string) Hook[*GRPCDump]

func MaskRequestBody

func MaskRequestBody(fields ...string) Hook[*HTTPDump]

func MaskRequestHeaders

func MaskRequestHeaders(headers ...string) Hook[*HTTPDump]

func MaskResponseBody

func MaskResponseBody(fields ...string) Hook[*HTTPDump]

func MaskResponseHeaders

func MaskResponseHeaders(headers ...string) Hook[*HTTPDump]

type Hooks

type Hooks[T any] []Hook[T]

func (Hooks[T]) Apply

func (hooks Hooks[T]) Apply(s S[T]) S[T]

type InMemory

type InMemory struct {
	Idempotent bool
	Data       []byte
}

func NewInMemory

func NewInMemory() *InMemory

func (*InMemory) Read

func (rw *InMemory) Read() ([]byte, error)

func (*InMemory) Write

func (rw *InMemory) Write(b []byte) error

type JSONComparer

type JSONComparer[T any] struct {
	Body []cmp.Option
}

func (*JSONComparer[T]) Compare

func (c *JSONComparer[T]) Compare(snapshot, received T) error

type JSONOption

type JSONOption struct {
	Body         []cmp.Option
	IgnoreFields []string
	MaskFields   []string
	CUEOption    *CUEOption
}

type MarshalFunc

type MarshalFunc[T any] (func(T) ([]byte, error))

func (MarshalFunc[T]) Marshal

func (f MarshalFunc[T]) Marshal(t T) ([]byte, error)

type MySQLComparer

type MySQLComparer struct {
	Args   []cmp.Option
	Vars   []cmp.Option
	Result []cmp.Option
}

func (*MySQLComparer) Compare

func (cmp *MySQLComparer) Compare(snapshot, received *SQL) error

type MySQLOption

type MySQLOption struct {
	Args   []cmp.Option
	Vars   []cmp.Option
	Result []cmp.Option
}

type PostgresComparer

type PostgresComparer struct {
	Args   []cmp.Option
	Vars   []cmp.Option
	Result []cmp.Option
}

func (*PostgresComparer) Compare

func (cmp *PostgresComparer) Compare(snapshot, received *SQL) error

type PostgresOption

type PostgresOption struct {
	Args   []cmp.Option
	Vars   []cmp.Option
	Result []cmp.Option
}

type RoundTripper

type RoundTripper struct {
	RoundTripper http.RoundTripper
	// contains filtered or unexported fields
}

func NewRoundTripper

func NewRoundTripper(rwFunc readerWriterFunc, opt *HTTPOption, hooks ...HTTPHook) *RoundTripper

func (*RoundTripper) RoundTrip

func (t *RoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

type S

type S[T any] interface {
	// contains filtered or unexported methods
}

type SQL

type SQL = sqldump.SQL

func UnmarshalMySQL

func UnmarshalMySQL(b []byte) (*SQL, error)

func UnmarshalPostgres

func UnmarshalPostgres(b []byte) (*SQL, error)

type TxTar

type TxTar struct {
	Name string
	File string
}

func NewTxTar

func NewTxTar(name, file string) *TxTar

func (*TxTar) Read

func (rw *TxTar) Read() ([]byte, error)

func (*TxTar) Write

func (rw *TxTar) Write(data []byte) error

type UnmarshalAnyFunc

type UnmarshalAnyFunc (func([]byte) (any, error))

func (UnmarshalAnyFunc) UnmarshalAny

func (f UnmarshalAnyFunc) UnmarshalAny(b []byte) (any, error)

type UnmarshalFunc

type UnmarshalFunc[T any] (func([]byte) (T, error))

func (UnmarshalFunc[T]) Unmarshal

func (f UnmarshalFunc[T]) Unmarshal(b []byte) (T, error)

type YAMLComparer

type YAMLComparer[T any] struct {
	Body []cmp.Option
}

func (*YAMLComparer[T]) Compare

func (c *YAMLComparer[T]) Compare(snapshot, received T) error

type YAMLOption

type YAMLOption struct {
	Body         []cmp.Option
	IgnoreFields []string
	MaskFields   []string
}

Jump to

Keyboard shortcuts

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