rose

module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2022 License: MIT

README

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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