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