golden provides utilities for golden file tests.

golden

pkg.go.dev

golden provides utilities for golden file tests.

package a_test

import (
	"flag"
	"os"
	"path/filepath"
	"testing"

	"github.com/tenntenn/golden"
)

var (
	flagUpdate bool
)

func init() {
	flag.BoolVar(&flagUpdate, "update", false, "update golden files")
}

func testTarget(dir string) error {
	if err := os.WriteFile(filepath.Join(dir, "a.txt"), []byte("hello"), 0700); err != nil {
		return err
	}

	if err := os.WriteFile(filepath.Join(dir, "b.txt"), []byte("world"), 0700); err != nil {
		return err
	}

	return nil
}

func Test(t *testing.T) {
	dir := t.TempDir()
	if err := testTarget(dir); err != nil {
		t.Fatal("unexpected error:", err)
	}

	got := golden.Txtar(dir)

	if flagUpdate {
		golden.Update(t, "testdata", "mytest", got)
		return
	}

	if diff := golden.Diff(t, "testdata", "mytest", got); diff != "" {
		t.Error(diff)
	}
}
Owner
Takuya Ueda
Go engineer / Gopher artist
Takuya Ueda
Similar Resources

List-Utils - 🔧 Utilities for maintaining the list of repost sites

SMR List Utils This is a Go CLI tool that helps with managing the StopModReposts blacklist. Install Use GitHub Releases and download binary. Linux Qui

Jan 3, 2022

Utilities for processing Wikipedia dumps in Go

Utilities for processing Wikipedia dumps in Go A Go package providing utilities for processing Wikipedia dumps. Features: Supports Wikidata entities J

Nov 29, 2022

Utilities for rounding and truncating floating point numbers.

Rounders Provides utilities for rounding and truncating floating point numbers. Example: rounders.RoundToDecimals(12.48881, 2)

Jan 6, 2022

Goety - Generics based Go utilities

goety General purpose Go utilities. Package channel Utilities to work with chann

May 16, 2022

Go-Utils is a library containing a collection of Golang utilities

Go-Utils is a library containing a collection of Golang utilities

Jun 2, 2022

rxscan provides functionality to scan text to variables using regular expression capture group.

rxscan rxscan provides functionality to scan text to variables using regular expression capture group. This library is still experimental, use at your

Dec 21, 2020

This project provides some working examples using Go and Hotwire Turbo.

hotwire-golang-website This project provides some working examples using Go the hotwire/turbo library published by basecamp.

Dec 29, 2022

Go library that provides fuzzy string matching optimized for filenames and code symbols in the style of Sublime Text, VSCode, IntelliJ IDEA et al.

Go library that provides fuzzy string matching optimized for filenames and code symbols in the style of Sublime Text, VSCode, IntelliJ IDEA et al.

Go library that provides fuzzy string matching optimized for filenames and code symbols in the style of Sublime Text, VSCode, IntelliJ IDEA et al. This library is external dependency-free. It only depends on the Go standard library.

Dec 27, 2022

Hotswap provides a solution for reloading your go code without restarting your server, interrupting or blocking any ongoing procedure.

Hotswap provides a solution for reloading your go code without restarting your server, interrupting or blocking any ongoing procedure.

Hotswap provides a solution for reloading your go code without restarting your server, interrupting or blocking any ongoing procedure. Hotswap is built upon the plugin mechanism.

Jan 5, 2023
Comments
  • Release for v0.4.0

    Release for v0.4.0

    This pull request is for the next release as v0.4.0 created by tagpr. Merging it will tag v0.4.0 to the merge commit and create a GitHub release.

    You can modify this branch "tagpr-from-v0.3.0" directly before merging if you want to change the next version number or other files for the release.

    How to change the next version as you like

    There are two ways to do it.

    • Version file
      • Edit and commit the version file specified in the .tagpr configuration file to describe the next version
      • If you want to use another version file, edit the configuration file.
    • Labels convention
      • Add labels to this pull request like "tagpr:minor" or "tagpr:major"
      • If no conventional labels are added, the patch version is incremented as is.

    What's Changed

    • Add TxtarJoin by @tenntenn in https://github.com/tenntenn/golden/pull/8

    Full Changelog: https://github.com/tenntenn/golden/compare/v0.3.0...v0.4.0

  • Release for v0.3.0

    Release for v0.3.0

    This pull request is for the next release as v0.3.0 created by tagpr. Merging it will tag v0.3.0 to the merge commit and create a GitHub release.

    You can modify this branch "tagpr-from-v0.2.0" directly before merging if you want to change the next version number or other files for the release.

    How to change the next version as you like

    There are two ways to do it.

    • Version file
      • Edit and commit the version file specified in the .tagpr configuration file to describe the next version
      • If you want to use another version file, edit the configuration file.
    • Labels convention
      • Add labels to this pull request like "tagpr:minor" or "tagpr:major"
      • If no conventional labels are added, the patch version is incremented as is.

    What's Changed

    • [fix]READMEのgolden.Txtarの引数が間違っていたので修正しました by @funera1 in https://github.com/tenntenn/golden/pull/3
    • Add tagpr by @tenntenn in https://github.com/tenntenn/golden/pull/5
    • Drop supporting for go1.17 by @tenntenn in https://github.com/tenntenn/golden/pull/7
    • Add check by @tenntenn in https://github.com/tenntenn/golden/pull/4

    New Contributors

    • @funera1 made their first contribution in https://github.com/tenntenn/golden/pull/3

    Full Changelog: https://github.com/tenntenn/golden/compare/v0.2.0...v0.3.0

Related tags
Go-path - A helper package that provides utilities for parsing and using ipfs paths

go-path is a helper package that provides utilities for parsing and using ipfs paths

Jan 18, 2022
A Go utility to convert Go example tests into jupyter notebooks.

go2colab Scientists (my main project's users) love jupyter notebook tutorials pkg.dev.go's runnable playground doesn't support file IO but I love exam

Jul 10, 2022
Flock is a project which provides a Go solution for system level file locks for all platforms Golang supports.

Flock is a project which provides a Go solution for system level file locks for all platforms Golang supports.

Feb 8, 2022
A collection of small Go utilities to make life easier.

The simplego package provides a collection of Go utilities for common tasks.

Jan 4, 2023
Utilities to generate (reference) documentation for the docker CLI

About This is a library containing utilities to generate (reference) documentation for the docker CLI on docs.docker.com. Disclaimer This library is i

Dec 28, 2022
Utilities for interacting with Dockerfiles
Utilities for interacting with Dockerfiles

go-dockerfile Golang utilities for interacting with Dockerfiles. This is not a place of honor. No esteemed source code is commemorated here. Don't tak

Apr 6, 2022
CUE utilities and helpers for working with tree based objects in any combination of CUE, Yaml, and JSON.

Cuetils CUE utilities and helpers for working with tree based objects in any combination of CUE, Yaml, and JSON. Using As a command line binary The cu

Dec 24, 2022
Simple utilities for creating ascii text in Go

Simple utilities for creating ascii text in Go

Oct 30, 2021
Source Repo for utilities used in Atlas

Atlas-Utilities Source Repo for utilities used in Atlas filepicker Simple file picker in Go using go-common-file-dialog This returns the path of a fil

Dec 25, 2022
Utilities and immutable collections for functional programming in Golang

Utilities and immutable collections for functional programming in Golang. This is an experimental library to play with the new Generics Feature in Go 1.18.

Sep 1, 2022