-
Notifications
You must be signed in to change notification settings - Fork 3
/
main_test.go
42 lines (34 loc) · 914 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
package main
import (
"context"
"fmt"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"io/ioutil"
"path/filepath"
"strings"
"testing"
)
func TestAllTheThings(t *testing.T) {
paths, err := filepath.Glob("testdata/*_input.json")
assert.NoError(t, err)
handler := New(nil)
for _, path := range paths {
base := filepath.Base(path)
t.Run(base, func(t *testing.T) {
if strings.HasPrefix(base, "skip_") {
t.SkipNow()
}
fragment, err := ioutil.ReadFile(path)
assert.NoError(t, err)
expected, err := ioutil.ReadFile(strings.Replace(path, "_input.json", "_result.json", 1))
assert.NoError(t, err)
input := &MacroInput{Fragment: fragment}
output, err := handler.Handle(context.Background(), input)
assert.NoError(t, err)
require.NotNil(t, output)
assert.JSONEq(t, string(expected), string(output.Fragment))
})
}
fmt.Println(paths)
}