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