root_test.go

 1//go:build !windows
 2
 3package commands_test
 4
 5import (
 6	"bytes"
 7	"io/ioutil"
 8	"path/filepath"
 9	"testing"
10
11	"github.com/stretchr/testify/require"
12)
13
14func requireGoldenFileEqual(t *testing.T, path string, act []byte) {
15	t.Helper()
16
17	// Replace Windows line terminators
18	act = bytes.ReplaceAll(act, []byte{'\r'}, []byte{})
19
20	path = filepath.Join("testdata", path)
21
22	if *update {
23		require.NoError(t, ioutil.WriteFile(path, act, 0644))
24	}
25
26	exp, err := ioutil.ReadFile(path)
27	require.NoError(t, err)
28	require.Equal(t, string(exp), string(act))
29}
30
31func TestNewRootCommand(t *testing.T) {
32	testEnv := newTestEnv(t)
33	testEnv.Execute(t)
34
35	requireGoldenFileEqual(t, "root_out_golden.txt", testEnv.out.Bytes())
36}