forked from dbaumgarten/yodk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamples_test.go
50 lines (45 loc) · 1.06 KB
/
examples_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
package main
import (
"io/ioutil"
"path/filepath"
"strings"
"testing"
yodktesting "github.com/dbaumgarten/yodk/pkg/testing"
)
func TestExamples(t *testing.T) {
runTestfiles(filepath.Join("examples", "yolol"), t)
runTestfiles(filepath.Join("examples", "nolol"), t)
runTestfiles("stdlib", t)
}
func runTestfiles(path string, t *testing.T) {
files, err := ioutil.ReadDir(path)
if err != nil {
t.Fatal(err)
}
testfiles := make([]string, 0, len(files))
for _, file := range files {
if !file.IsDir() && strings.HasSuffix(file.Name(), "_test.yaml") {
testfiles = append(testfiles, filepath.Join(path, file.Name()))
}
}
for _, testfile := range testfiles {
t.Run(testfile, func(t *testing.T) {
file, err := ioutil.ReadFile(testfile)
if err != nil {
t.Fatal(err)
}
absolutePath, _ := filepath.Abs(testfile)
test, err := yodktesting.Parse([]byte(file), absolutePath)
if err != nil {
t.Fatal(err)
}
fails := test.Run(nil)
if len(fails) != 0 {
for _, fail := range fails {
t.Log(fail)
}
t.FailNow()
}
})
}
}