github.com/quay/claircore@v1.5.28/scanner/pkgconfig/scanner_test.go (about)

     1  package pkgconfig
     2  
     3  import (
     4  	"os"
     5  	"path"
     6  	"testing"
     7  
     8  	"github.com/google/go-cmp/cmp"
     9  )
    10  
    11  type scannerTestcase struct {
    12  	File string
    13  	Want pc
    14  }
    15  
    16  func (tc scannerTestcase) Run(t *testing.T) {
    17  	t.Parallel()
    18  	var got pc
    19  	f, err := os.Open(tc.File)
    20  	if err != nil {
    21  		t.Fatal(err)
    22  	}
    23  	defer f.Close()
    24  
    25  	if err := got.Scan(f); err != nil {
    26  		t.Error(err)
    27  	}
    28  	if !cmp.Equal(tc.Want, got) {
    29  		t.Error(cmp.Diff(tc.Want, got))
    30  	}
    31  }
    32  
    33  func TestScanner(t *testing.T) {
    34  	tt := []scannerTestcase{
    35  		scannerTestcase{
    36  			File: "testdata/bash-completion.pc",
    37  			Want: pc{
    38  				Name:    "bash-completion",
    39  				Version: "2.8",
    40  				URL:     "https://github.com/scop/bash-completion",
    41  			},
    42  		},
    43  		scannerTestcase{
    44  			File: "testdata/dracut.pc",
    45  			Want: pc{
    46  				Name:    "dracut",
    47  				Version: "64fefc221cf13e858d4921be7f0b1eea86c364d2",
    48  			},
    49  		},
    50  		scannerTestcase{
    51  			File: "testdata/libpng.pc",
    52  			Want: pc{Name: "libpng", Version: "1.6.37"},
    53  		},
    54  		scannerTestcase{
    55  			File: "testdata/shared-mime-info.pc",
    56  			Want: pc{Name: "shared-mime-info", Version: "1.15"},
    57  		},
    58  		scannerTestcase{
    59  			File: "testdata/systemd.pc",
    60  			Want: pc{
    61  				Name:    "systemd",
    62  				Version: "243",
    63  				URL:     "https://www.freedesktop.org/wiki/Software/systemd",
    64  			},
    65  		},
    66  		scannerTestcase{
    67  			File: "testdata/udev.pc",
    68  			Want: pc{Name: "udev", Version: "243"},
    69  		},
    70  	}
    71  
    72  	for _, tc := range tt {
    73  		t.Run(path.Base(tc.File), tc.Run)
    74  	}
    75  }