mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-04 03:11:55 +02:00
d2a63c1093
Signed-off-by: Engin Diri <engin.diri@mail.schwarz>
59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
// Package golden asserts golden files contents.
|
|
package golden
|
|
|
|
import (
|
|
"flag"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
var update = flag.Bool("update", false, "update .golden files")
|
|
|
|
func RequireEqual(tb testing.TB, out []byte) {
|
|
tb.Helper()
|
|
doRequireEqual(tb, out, "")
|
|
}
|
|
|
|
func RequireEqualTxt(tb testing.TB, out []byte) {
|
|
tb.Helper()
|
|
doRequireEqual(tb, out, ".txt")
|
|
}
|
|
|
|
func RequireEqualJSON(tb testing.TB, out []byte) {
|
|
tb.Helper()
|
|
doRequireEqual(tb, out, ".json")
|
|
}
|
|
|
|
func RequireEqualRb(tb testing.TB, out []byte) {
|
|
tb.Helper()
|
|
doRequireEqual(tb, out, ".rb")
|
|
}
|
|
|
|
func RequireEqualLua(tb testing.TB, out []byte) {
|
|
tb.Helper()
|
|
doRequireEqual(tb, out, ".lua")
|
|
}
|
|
|
|
func RequireEqualYaml(tb testing.TB, out []byte) {
|
|
tb.Helper()
|
|
doRequireEqual(tb, out, ".yml")
|
|
}
|
|
|
|
func doRequireEqual(tb testing.TB, out []byte, ext string) {
|
|
tb.Helper()
|
|
|
|
golden := "testdata/" + tb.Name() + ext + ".golden"
|
|
if *update {
|
|
require.NoError(tb, os.MkdirAll(filepath.Dir(golden), 0o755))
|
|
require.NoError(tb, os.WriteFile(golden, out, 0o655))
|
|
}
|
|
|
|
gbts, err := os.ReadFile(golden)
|
|
require.NoError(tb, err)
|
|
|
|
require.Equal(tb, string(gbts), string(out))
|
|
}
|