-
-
Notifications
You must be signed in to change notification settings - Fork 105
/
run.go
36 lines (30 loc) · 909 Bytes
/
run.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
package migratest
import (
"encoding/json"
"io/ioutil"
"path/filepath"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func ContainsExpectedIds(t *testing.T, path string, ids []string) {
files, err := ioutil.ReadDir(path)
require.NoError(t, err)
for _, f := range files {
if filepath.Ext(f.Name()) == ".json" {
expected := strings.TrimSuffix(filepath.Base(f.Name()), ".json")
assert.Contains(t, ids, expected)
}
}
}
func CompareWithFixture(t *testing.T, actual interface{}, prefix string, id string) {
location := filepath.Join("fixtures", prefix, id+".json")
expected, err := ioutil.ReadFile(location)
WriteFixtureOnError(t, err, actual, location)
actualJSON, err := json.Marshal(actual)
require.NoError(t, err)
if !assert.JSONEq(t, string(expected), string(actualJSON)) {
WriteFixtureOnError(t, nil, actual, location)
}
}