...

Package snapshot

import "edge-infra.dev/test/snapshot"
Overview
Index
Subdirectories

Overview ▾

Package snapshot implements Go snapshot testing by writing expected test results to files (a snapshot of the expected results) and comparing actual test output against those files. If the actual test output differs from the snapshot, the differences between the two are printed to the user for debugging.

This package drew inspiration from github.com/bradleyjkemp/cupaloy/v2 while using github.com/pmezard/go-difflib/difflib to retrieve and display diffs.

Variables

var (
    // Public Errors
    ErrSnapshotCreated = fmt.Errorf("snapshot(s) created. Please rerun your tests")
    ErrSnapshotUpdated = fmt.Errorf("snapshot(s) updated. Please rerun your tests")
    ErrMismatch        = fmt.Errorf("expected snapshot differs from actual")
)

func Snap

func Snap(t *testing.T, a any)

Snap is the actual call used in tests (i.e. snapshot.Snap(t, result)), which calls a version of Snap that uses Config as a receiver. Only one interface should be passed to snap at a time such that only one snapshot is created, updated, or compared to at a time. Table-driven-tests can be utilized to create, update, or compare one snapshot per test case.

Subdirectories

Name Synopsis
..
examples