snap

package module
v0.0.0-...-476ebd7 Latest Latest
Warning

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

Go to latest
Published: May 2, 2021 License: MIT Imports: 7 Imported by: 0

README

snap

Snap is snapshot testing library.

Usage

You can update snapshot via go test ./... -update.

Examples
func TestSnapshot(t *testing.T) {
	s := New()
	_ = s.Snapshot("xxx")
	_ = s.Snapshot("xxx")
	_ = s.Snapshot("xxxy")
	s.Assert(t)
}

func TestSnapshotBytes(t *testing.T) {
	s := New()
	_ = s.SnapshotBytes([]byte("吉野家"))
	s.Assert(t)
}

func TestCanUseAsIoWriter(t *testing.T) {
	s := New()
	b := bytes.NewBufferString("test")
	_, _ = io.Copy(s, b)
	s.Assert(t)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	UpdateSnapshot bool
}

func NewConfig

func NewConfig(options ...Option) *Config

type Option

type Option func(c Config) Config

type SnapshotTester

type SnapshotTester struct {
	// contains filtered or unexported fields
}

func New

func New(options ...Option) *SnapshotTester

New returns new SnapshotTester.

func (*SnapshotTester) Assert

func (s *SnapshotTester) Assert(t testingT)

Assert reports error if current snapshot differs from older one.

func (*SnapshotTester) Snapshot

func (s *SnapshotTester) Snapshot(value string) error

Snapshot writes value as snapshot.

func (*SnapshotTester) SnapshotBytes

func (s *SnapshotTester) SnapshotBytes(bs []byte) error

SnapshotBytes writes bytes as snapshot.

func (*SnapshotTester) Write

func (s *SnapshotTester) Write(p []byte) (n int, err error)

Write writes bytes.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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