/rose

Rose is a golden file utility library for your Go tests.

Primary LanguageGoMIT LicenseMIT

Tests codecov Go Report Card GoDoc

Rose

Rose is a golden file utility library for your Go tests.

It handles the dirty work so your tests stay concise and readable.

  • Normalizes common file formats
  • Helps organize files with per-test path prefixes
  • Leaves you in control of supplying the update flag

Usage

package mypackage

import (
	"flag"
	"testing"

	"github.com/eberkund/rose/gold"
)

// Use `go test ./... -update` to write new files with supplied data
var update = flag.Bool("update", false, "update golden files")

func TestFiles(t *testing.T) {
    g := gold.New(
        t,

        // Pass the update flag to Gold constructor
        gold.WithFlag(*update),

        // Store files in `testdata/<test name>/<file name>`
        // Prefix defaults to `testdata`
        gold.WithPrefix("testdata", t.Name()),
    )

    // Provide the filename and input data
    g.AssertEqualsJSON("somefile.golden.json", `{"foo": 123}`)
}