golden_image

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2022 License: MIT Imports: 15 Imported by: 0

README ¶

GoldenImage

GitHub go.mod Go version of a Go module GoDoc reference example

Snapshot-testing tool with build-in image comparison

Banner

Installation

To install golden-image, simply use go get:

$> go get github.com/opa-oz/golden-image

Usage

Hungry for image comparison in your autotests? Simply gild your images for the first time and enjoy comparison

import (
    goldenImage "github.com/opa-oz/golden-image"
    "testing"
)

func TestGet(t *testing.T) {
    firstImage, err := GetImage(1) // image.Image type
    if err != nil {
        t.Error(err)
        return
    }
    
    secondImage, err2 := GetImage(2)
    if err2 != nil {
        t.Error(err2)
        return
    }
    
    t.Run("should compare first to first", func (t *testing.T) {
        goldenImage.ToGildImage(t, 0.02, golden) // compare image to gilded one, or gild if it's not existing yet
    })
    
    t.Run("should compare second to second", func (t *testing.T) {
        goldenImage.ToMatchSnapshot(t, 0.02, copper) // you can also use alisa `ToMatchSnapshot`
    })
}

You will find your baseline images (a.k.a. gilded images) inside __baseimage__

But...

If your image has differences with the golden-set's image, you'll get conveniently printed FAIL:

--- FAIL: TestGet (0.63s)
    --- FAIL: TestGet/should_compare_first_to_first (0.50s)
        main_test.go:22: • Found diff: 0.474205.
            Highlights are stored at .../__baseimages__/__diffs__/main_test.[TestGet-should_compare_first_to_first-0001].png.

And what is highlights you may ask?

Let's pretend this is our original image (the gilded one):

Original

And after our image generation algorithm it was slightly changed:

Original

In this case, your comparison will fail and we'll see the difference, highlighted like that:

Original

Update?

Of course, you can update gilded images, just casually run:

$> UPDATE_SNAPS=true go test

Cheers 🥂

Documentation ¶

Index ¶

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

func ToGildImage ¶

func ToGildImage(t *testing.T, threshold float64, values ...image.Image)

func ToMatchSnapshot ¶ added in v0.1.3

func ToMatchSnapshot(t *testing.T, threshold float64, values ...image.Image)

Types ¶

type SyncRegistry ¶

type SyncRegistry struct {
	sync.Mutex
	// contains filtered or unexported fields
}

SyncRegistry tracks occurrence as in the same test we can run multiple snapshots This also helps with keeping track with obsolete snaps map[snap path]: map[testname]: <number of snapshots>

type SyncSlice ¶

type SyncSlice struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Directories ¶

Path Synopsis

Jump to

Keyboard shortcuts

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