github.com/icyphox/x@v0.0.355-0.20220311094250-029bd783e8b8/migratest/run.go (about) 1 package migratest 2 3 import ( 4 "encoding/json" 5 "io/ioutil" 6 "path/filepath" 7 "strings" 8 "testing" 9 10 "github.com/stretchr/testify/assert" 11 "github.com/stretchr/testify/require" 12 ) 13 14 func ContainsExpectedIds(t *testing.T, path string, ids []string) { 15 files, err := ioutil.ReadDir(path) 16 require.NoError(t, err) 17 18 for _, f := range files { 19 if filepath.Ext(f.Name()) == ".json" { 20 expected := strings.TrimSuffix(filepath.Base(f.Name()), ".json") 21 assert.Contains(t, ids, expected) 22 } 23 } 24 } 25 func CompareWithFixture(t *testing.T, actual interface{}, prefix string, id string) { 26 location := filepath.Join("fixtures", prefix, id+".json") 27 expected, err := ioutil.ReadFile(location) 28 WriteFixtureOnError(t, err, actual, location) 29 30 actualJSON, err := json.Marshal(actual) 31 require.NoError(t, err) 32 33 if !assert.JSONEq(t, string(expected), string(actualJSON)) { 34 WriteFixtureOnError(t, nil, actual, location) 35 } 36 }