github.com/quay/claircore@v1.5.28/alpine/distributionscanner_test.go (about) 1 package alpine 2 3 import ( 4 "context" 5 "encoding/json" 6 "io/fs" 7 "os" 8 "testing" 9 10 "github.com/google/go-cmp/cmp" 11 "github.com/quay/zlog" 12 13 "github.com/quay/claircore" 14 ) 15 16 func TestScanFs(t *testing.T) { 17 ctx := context.Background() 18 ctx = zlog.Test(ctx, t) 19 20 td := os.DirFS("testdata") 21 ms, err := fs.Glob(td, "3.*") 22 if err != nil { 23 t.Fatal(err) 24 } 25 edge, err := fs.Glob(td, "edge") 26 if err != nil { 27 t.Fatal(err) 28 } 29 for _, v := range append(ms, edge...) { 30 sub, err := fs.Sub(td, v) 31 if err != nil { 32 t.Fatal(err) 33 } 34 t.Run(v, scanFsTestcase(ctx, sub)) 35 } 36 } 37 38 func scanFsTestcase(ctx context.Context, sys fs.FS) func(*testing.T) { 39 var s DistributionScanner 40 var want []*claircore.Distribution 41 in, err := fs.ReadFile(sys, "want") 42 if err == nil { 43 err = json.Unmarshal(in, &want) 44 } 45 return func(t *testing.T) { 46 if err != nil { 47 t.Fatal(err) 48 } 49 ctx := zlog.Test(ctx, t) 50 got, err := s.scanFs(ctx, sys) 51 if err != nil { 52 t.Error(err) 53 } 54 if !cmp.Equal(got, want) { 55 t.Error(cmp.Diff(got, want)) 56 } 57 } 58 }