github.com/lineaje-labs/syft@v0.98.1-0.20231227153149-9e393f60ff1b/syft/pkg/cataloger/java/zip_wrapped_archive_parser_test.go (about)

     1  package java
     2  
     3  import (
     4  	"os"
     5  	"path"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  	"github.com/stretchr/testify/require"
    10  
    11  	"github.com/anchore/syft/syft/file"
    12  )
    13  
    14  func Test_parseZipWrappedJavaArchive(t *testing.T) {
    15  	tests := []struct {
    16  		fixture  string
    17  		expected []string
    18  	}{
    19  		{
    20  			fixture: "test-fixtures/java-builds/packages/example-java-app-maven-0.1.0.zip",
    21  			expected: []string{
    22  				"example-java-app-maven",
    23  				"joda-time",
    24  			},
    25  		},
    26  	}
    27  	for _, test := range tests {
    28  		t.Run(path.Base(test.fixture), func(t *testing.T) {
    29  			generateJavaBuildFixture(t, test.fixture)
    30  
    31  			fixture, err := os.Open(test.fixture)
    32  			if err != nil {
    33  				t.Fatalf("failed to open fixture: %+v", err)
    34  			}
    35  
    36  			gzp := newGenericZipWrappedJavaArchiveParser(ArchiveCatalogerConfig{})
    37  
    38  			actualPkgs, _, err := gzp.parseZipWrappedJavaArchive(nil, nil, file.LocationReadCloser{
    39  				Location:   file.NewLocation(test.fixture),
    40  				ReadCloser: fixture,
    41  			})
    42  			require.NoError(t, err)
    43  
    44  			var actualNames []string
    45  			for _, p := range actualPkgs {
    46  				actualNames = append(actualNames, p.Name)
    47  			}
    48  
    49  			assert.ElementsMatch(t, test.expected, actualNames)
    50  		})
    51  	}
    52  }