github.com/quay/claircore@v1.5.28/rhel/distributionscanner_test.go (about)

     1  package rhel
     2  
     3  import (
     4  	"io/fs"
     5  	"os"
     6  	"path"
     7  	"strings"
     8  	"testing"
     9  )
    10  
    11  func TestDistributionScanner(t *testing.T) {
    12  	sys := os.DirFS(`testdata/releasefiles`)
    13  	ents, err := fs.ReadDir(sys, ".")
    14  	if err != nil {
    15  		t.Fatal(err)
    16  	}
    17  	for _, e := range ents {
    18  		t.Run(e.Name(), func(t *testing.T) {
    19  			n := path.Base(t.Name())
    20  			sys, err := fs.Sub(sys, n)
    21  			if err != nil {
    22  				t.Fatal(err)
    23  			}
    24  			d, err := findDistribution(sys)
    25  			if err != nil {
    26  				t.Fatal(err)
    27  			}
    28  			switch {
    29  			case strings.HasPrefix(n, "oracle-"):
    30  				if d != nil {
    31  					t.Fatalf("incorrect distribution: %s:%s", d.DID, d.VersionID)
    32  				}
    33  			default:
    34  				if d == nil {
    35  					t.Fatal("missing distribution")
    36  				}
    37  				if got, want := d.Version, strings.TrimPrefix(n, "atomichost-"); got != want {
    38  					t.Errorf("got: %q, want %q", got, want)
    39  				}
    40  			}
    41  		})
    42  	}
    43  }