github.com/quay/claircore@v1.5.28/debian/distributionscanner_test.go (about) 1 package debian 2 3 import ( 4 "context" 5 "io/fs" 6 "os" 7 "path/filepath" 8 "regexp" 9 "testing" 10 11 "github.com/quay/zlog" 12 ) 13 14 func TestDistributionScanner(t *testing.T) { 15 ver := regexp.MustCompile(`^\d+ \(\w+\)$`) 16 ctx := zlog.Test(context.Background(), t) 17 ents, err := os.ReadDir(`testdata/dist`) 18 if err != nil { 19 t.Fatal(err) 20 } 21 dEnts, err := os.ReadDir(`testdata/distroless_dist`) 22 if err != nil { 23 t.Fatal(err) 24 } 25 26 testCase := map[string][]fs.DirEntry{ 27 "testdata/dist": ents, 28 "testdata/distroless_dist": dEnts, 29 } 30 31 for tcDir, tcEnts := range testCase { 32 for _, e := range tcEnts { 33 t.Run(e.Name(), func(t *testing.T) { 34 sys := os.DirFS(filepath.Join(tcDir, e.Name())) 35 d, err := findDist(ctx, sys) 36 if err != nil { 37 t.Error(err) 38 } 39 if d == nil { 40 t.Fatalf("tc: %v | %s does not represent a Debian dist", tcDir, e.Name()) 41 } 42 got, want := d.VersionID, e.Name() 43 t.Logf("tc: %v | got: %q, want: %q", tcDir, got, want) 44 if got != want { 45 t.Fail() 46 } 47 if !ver.MatchString(d.Version) { 48 t.Fatalf("tc: %v | weird version: %q", tcDir, d.Version) 49 } 50 }) 51 } 52 } 53 }