-
Notifications
You must be signed in to change notification settings - Fork 2
/
main_test.go
53 lines (42 loc) · 1009 Bytes
/
main_test.go
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"bytes"
"io"
"os"
"path/filepath"
"sync"
"testing"
"github.com/stretchr/testify/require"
)
func TestMain0(t *testing.T) {
files, err := filepath.Glob(filepath.Join("testdata", "*"))
require.NoError(t, err)
for _, filename := range files {
filename := filename
t.Run(filename, func(t *testing.T) {
defer func(orig *os.File) {
os.Stdout = orig
}(os.Stdout)
r, w, err := os.Pipe()
require.NoError(t, err)
var copyErr error
buf := bytes.NewBuffer(nil)
wg := sync.WaitGroup{}
wg.Add(1)
go func() {
defer wg.Done()
_, copyErr = io.Copy(buf, r)
}()
os.Stdout = w
err = main0([]string{"tfreveal", "--no-color", filepath.Join(filename, "plan.json")})
require.NoError(t, err)
err = w.Close()
require.NoError(t, err)
want, err := os.ReadFile(filepath.Join(filename, "output.golden"))
require.NoError(t, err)
wg.Wait()
require.NoError(t, copyErr)
require.Equal(t, string(want), buf.String())
})
}
}