1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2024-12-31 01:53:50 +02:00
goreleaser/internal/golden/golden.go

76 lines
1.7 KiB
Go
Raw Normal View History

// 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")
const golden = ".golden"
func RequireEqual(tb testing.TB, out []byte) {
tb.Helper()
feat: arch user repository integration (#2838) * feat: aur PKGBUILD integration Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * feat: guess install, improve formatting Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * fix: more deterministic Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * feat: binary releases, push, more tests Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * feat: accept key as text Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * feat: improvements Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * feat: srcinfo Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * fix: compile Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * fix: everything Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * fix: lint Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * feat: renames, docs, etc Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * docs: link to docs Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * fix: go mod tidy, title Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * fix: srcinfo tmpl Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * fix: missing close quote Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * fix: templates Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * fix: always defaults conflicts and provides Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * fix: ssh command Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * fix: maintainers can be a list Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * fix: ensure -bin suffix, more tests and docs Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * fix: this will never happen Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * fix: whitespaces Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * fix: goreleaser config Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
2022-01-20 19:59:39 +02:00
RequireEqualExt(tb, out, "")
}
func RequireEqualExt(tb testing.TB, out []byte, ext string) {
tb.Helper()
doRequireEqual(tb, out, ext, golden, false)
}
func RequireEqualExtSubfolder(tb testing.TB, out []byte, ext string) {
tb.Helper()
doRequireEqual(tb, out, ext, golden, true)
}
func RequireEqualTxt(tb testing.TB, out []byte) {
tb.Helper()
doRequireEqual(tb, out, ".txt", golden, false)
}
func RequireEqualJSON(tb testing.TB, out []byte) {
tb.Helper()
doRequireEqual(tb, out, ".json", golden, false)
}
func RequireEqualRb(tb testing.TB, out []byte) {
tb.Helper()
doRequireEqual(tb, out, ".rb", golden, false)
}
func RequireEqualYaml(tb testing.TB, out []byte) {
tb.Helper()
doRequireEqual(tb, out, ".yaml", "", false)
}
func RequireReadFile(tb testing.TB, path string) []byte {
tb.Helper()
bts, err := os.ReadFile(path)
require.NoError(tb, err)
return bts
}
func doRequireEqual(tb testing.TB, out []byte, ext, suffix string, folder bool) {
tb.Helper()
golden := filepath.Join("testdata", tb.Name()+ext+suffix)
if folder {
golden = filepath.Join("testdata", tb.Name(), filepath.Base(tb.Name())+ext+suffix)
}
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))
}