github.com/metasources/buildx@v0.0.0-20230418141019-7aa1459cedea/test/integration/regression_go_bin_scanner_arch_test.go (about)

     1  package integration
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  
     7  	"github.com/metasources/buildx/buildx/pkg"
     8  	"github.com/metasources/buildx/buildx/source"
     9  )
    10  
    11  func TestRegressionGoArchDiscovery(t *testing.T) {
    12  	const (
    13  		expectedELFPkg   = 4
    14  		expectedWINPkg   = 4
    15  		expectedMACOSPkg = 4
    16  	)
    17  	// This is a regression test to make sure the way we detect go binary packages
    18  	// stays consistent and reproducible as the tool chain evolves
    19  	sbom, _ := catalogFixtureImage(t, "image-go-bin-arch-coverage", source.SquashedScope, nil)
    20  
    21  	var actualELF, actualWIN, actualMACOS int
    22  
    23  	for p := range sbom.Artifacts.PackageCatalog.Enumerate(pkg.GoModulePkg) {
    24  		for _, l := range p.Locations.ToSlice() {
    25  			switch {
    26  			case strings.Contains(l.RealPath, "elf"):
    27  				actualELF++
    28  			case strings.Contains(l.RealPath, "win"):
    29  				actualWIN++
    30  			case strings.Contains(l.RealPath, "macos"):
    31  				actualMACOS++
    32  			default:
    33  
    34  			}
    35  		}
    36  	}
    37  
    38  	if actualELF != expectedELFPkg {
    39  		t.Errorf("unexpected number of elf packages: %d != %d", expectedELFPkg, actualELF)
    40  	}
    41  
    42  	if actualWIN != expectedWINPkg {
    43  		t.Errorf("unexpected number of win packages: %d != %d", expectedWINPkg, actualWIN)
    44  	}
    45  
    46  	if actualMACOS != expectedMACOSPkg {
    47  		t.Errorf("unexpected number of macos packages: %d != %d", expectedMACOSPkg, actualMACOS)
    48  	}
    49  }