goldga

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2022 License: Apache-2.0 Imports: 21 Imported by: 0

README

Goldga

GoDoc GitHub release CircleCI codecov

A golden file testing (snapshot testing) library for gomega.

Installation

go get github.com/tommy351/goldga

Usage

import (
  . "github.com/onsi/ginkgo/v2"
  . "github.com/onsi/gomega"
  "github.com/tommy351/goldga"
)

Describe("Example", func() {
  It("works", func() {
    Expect("foobar").To(goldga.Match())
  })
})

See examples folder for more examples.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ColorDiffer added in v0.2.0

type ColorDiffer struct{}

func (ColorDiffer) Diff added in v0.2.0

func (ColorDiffer) Diff(snapshot, received []byte) []byte

type Differ added in v0.2.0

type Differ interface {
	Diff(snapshot, received []byte) []byte
}
var (
	DefaultDiffer Differ = &ColorDiffer{}
)

nolint: gochecknoglobals

type DumpSerializer

type DumpSerializer struct {
	Config *spew.ConfigState
}

func (*DumpSerializer) Serialize

func (d *DumpSerializer) Serialize(w io.Writer, input interface{}) error

type JSONSerializer

type JSONSerializer struct {
	EscapeHTML   bool
	IndentPrefix string
	Indent       string
}

func (*JSONSerializer) Serialize

func (j *JSONSerializer) Serialize(w io.Writer, input interface{}) error

type Matcher

type Matcher struct {
	Serializer  Serializer
	Transformer Transformer
	Storage     Storage
	Differ      Differ
	UpdateFile  bool
}

func Match

func Match(options ...Option) *Matcher

func (*Matcher) FailureMessage

func (m *Matcher) FailureMessage(actual interface{}) string

func (*Matcher) Match

func (m *Matcher) Match(actual interface{}) (bool, error)

func (*Matcher) NegatedFailureMessage

func (m *Matcher) NegatedFailureMessage(actual interface{}) string

type NopTransformer

type NopTransformer struct{}

func (NopTransformer) Transform

func (NopTransformer) Transform(input interface{}) (interface{}, error)

type Option added in v0.3.0

type Option func(*Matcher)

func WithDescription added in v0.3.0

func WithDescription(description string) Option

WithDescription adds an optional description to the golden file, allowing multiple gold files per test.

func WithDiffer added in v0.4.0

func WithDiffer(differ Differ) Option

WithDiffer overrides the default differ.

func WithSerializer added in v0.4.0

func WithSerializer(serializer Serializer) Option

WithSerializer overrides the default serializer.

func WithStorage added in v0.4.0

func WithStorage(storage Storage) Option

WithStorage overrides the default storage.

func WithTransformer added in v0.4.0

func WithTransformer(transformer Transformer) Option

WithTransformer overrides the default transformer.

type Serializer

type Serializer interface {
	Serialize(w io.Writer, input interface{}) error
}
var (
	DefaultSerializer Serializer = &DumpSerializer{
		Config: newDefaultDumpConfig(),
	}
)

nolint: gochecknoglobals

type SingleStorage added in v0.2.0

type SingleStorage struct {
	Path string
	Fs   afero.Fs
}

func (*SingleStorage) Read added in v0.2.0

func (s *SingleStorage) Read() ([]byte, error)

func (*SingleStorage) Write added in v0.2.0

func (s *SingleStorage) Write(data []byte) error

type Storage added in v0.2.0

type Storage interface {
	Read() ([]byte, error)
	Write(data []byte) error
}

type StringSerializer added in v0.4.0

type StringSerializer struct {
	FallbackSerializer Serializer
}

func (*StringSerializer) Serialize added in v0.4.0

func (s *StringSerializer) Serialize(w io.Writer, input interface{}) error

type SuiteStorage added in v0.2.0

type SuiteStorage struct {
	Path string
	Name string
	Fs   afero.Fs
}

func (*SuiteStorage) Read added in v0.2.0

func (s *SuiteStorage) Read() ([]byte, error)

func (*SuiteStorage) Write added in v0.2.0

func (s *SuiteStorage) Write(input []byte) error

type TOMLSerializer

type TOMLSerializer struct {
	Indent string
}

func (*TOMLSerializer) Serialize

func (t *TOMLSerializer) Serialize(w io.Writer, input interface{}) error

type Transformer

type Transformer interface {
	Transform(input interface{}) (interface{}, error)
}
var (
	DefaultTransformer Transformer = &NopTransformer{}
)

nolint: gochecknoglobals

type YAMLSerializer

type YAMLSerializer struct{}

func (*YAMLSerializer) Serialize

func (y *YAMLSerializer) Serialize(w io.Writer, input interface{}) error

Jump to

Keyboard shortcuts

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