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