github.com/icyphox/x@v0.0.355-0.20220311094250-029bd783e8b8/snapshotx/snapshot_test.go (about) 1 package snapshotx 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "io/fs" 7 "os" 8 "path/filepath" 9 "testing" 10 11 "github.com/stretchr/testify/require" 12 ) 13 14 func TestDeleteMatches(t *testing.T) { 15 files := map[string][]byte{} 16 // Iterate over all json files 17 require.NoError(t, filepath.Walk("fixtures", func(path string, info fs.FileInfo, err error) error { 18 if err != nil { 19 return err 20 } 21 22 if info.IsDir() { 23 return nil 24 } 25 26 if filepath.Ext(path) != ".json" { 27 return nil 28 } 29 30 f, err := os.ReadFile(path) 31 if err != nil { 32 return err 33 } 34 files[info.Name()] = f 35 return nil 36 })) 37 38 for k, f := range files { 39 t.Run(fmt.Sprintf("file=%s/fn", k), func(t *testing.T) { 40 var tc struct { 41 Content json.RawMessage `json:"content"` 42 Ignore []string `json:"ignore"` 43 } 44 require.NoError(t, json.Unmarshal(f, &tc)) 45 SnapshotTExceptMatchingKeys(t, tc.Content, tc.Ignore) 46 }) 47 } 48 }