-
Notifications
You must be signed in to change notification settings - Fork 2
/
main_test.go
51 lines (42 loc) · 905 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
package main
import (
"fmt"
"os"
"os/exec"
"testing"
"github.com/ghodss/yaml"
"github.com/stretchr/testify/assert"
)
type (
Tests []E2E
E2E struct {
Title string `yaml:"title"`
Arguments []string `yaml:"arguments"`
Output string `yaml:"output"`
}
)
func Test_main(t *testing.T) {
table := Tests{}
tests, err := os.ReadFile("./testdata/tests.yaml")
dieOnError(err)
err = yaml.Unmarshal(tests, &table)
dieOnError(err)
for _, test := range table {
fmt.Println(test.Title)
t.Run(test.Title, func(tt *testing.T) {
fmt.Println("Running test")
pikolo := exec.Command("/tmp/pikolo-test", test.Arguments...)
out, err := pikolo.Output()
if err != nil {
assert.Fail(tt, "Should not fail")
}
assert.Equal(tt, test.Output, string(out))
})
}
}
func dieOnError(err error) {
if err != nil {
fmt.Printf("Error: %s\n", err.Error())
os.Exit(1)
}
}