github.com/noqcks/syft@v0.0.0-20230920222752-a9e2c4e288e5/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  			actualPkgs, _, err := parseZipWrappedJavaArchive(nil, nil, file.LocationReadCloser{
    37  				Location:   file.NewLocation(test.fixture),
    38  				ReadCloser: fixture,
    39  			})
    40  			require.NoError(t, err)
    41  
    42  			var actualNames []string
    43  			for _, p := range actualPkgs {
    44  				actualNames = append(actualNames, p.Name)
    45  			}
    46  
    47  			assert.ElementsMatch(t, test.expected, actualNames)
    48  		})
    49  	}
    50  }