github.com/anchore/syft@v1.38.2/syft/pkg/cataloger/githubactions/parse_composite_action_test.go (about)

     1  package githubactions
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/anchore/syft/syft/artifact"
     7  	"github.com/anchore/syft/syft/file"
     8  	"github.com/anchore/syft/syft/pkg"
     9  	"github.com/anchore/syft/syft/pkg/cataloger/internal/pkgtest"
    10  )
    11  
    12  func Test_parseCompositeActionForActionUsage(t *testing.T) {
    13  	fixture := "test-fixtures/composite-action.yaml"
    14  	fixtureLocationSet := file.NewLocationSet(file.NewLocation(fixture).WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation))
    15  
    16  	expected := []pkg.Package{
    17  		{
    18  			Name:      "actions/setup-go",
    19  			Version:   "v4",
    20  			Type:      pkg.GithubActionPkg,
    21  			Locations: fixtureLocationSet,
    22  			PURL:      "pkg:github/actions/setup-go@v4",
    23  			Metadata:  pkg.GitHubActionsUseStatement{Value: "actions/setup-go@v4"},
    24  		},
    25  		{
    26  			Name:      "actions/cache",
    27  			Version:   "v3",
    28  			Type:      pkg.GithubActionPkg,
    29  			Locations: fixtureLocationSet,
    30  			PURL:      "pkg:github/actions/cache@v3",
    31  			Metadata:  pkg.GitHubActionsUseStatement{Value: "actions/cache@v3"},
    32  		},
    33  	}
    34  
    35  	var expectedRelationships []artifact.Relationship
    36  	pkgtest.TestFileParser(t, fixture, parseCompositeActionForActionUsage, expected, expectedRelationships)
    37  }
    38  
    39  func Test_corruptCompositeAction(t *testing.T) {
    40  	pkgtest.NewCatalogTester().
    41  		FromFile(t, "test-fixtures/corrupt/composite-action.yaml").
    42  		WithError().
    43  		TestParser(t, parseCompositeActionForActionUsage)
    44  }