Skip to content
/ rose Public

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

License

Notifications You must be signed in to change notification settings

eberkund/rose

Repository files navigation

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}`)
}

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published