github.com/nextlinux/gosbom@v0.81.1-0.20230627115839-1ff50c281391/gosbom/pkg/cataloger/java/tar_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_parseTarWrappedJavaArchive(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.tar", 20 expected: []string{ 21 "example-java-app-maven", 22 "joda-time", 23 }, 24 }, 25 { 26 fixture: "test-fixtures/java-builds/packages/example-java-app-maven-0.1.0.tar.gz", 27 expected: []string{ 28 "example-java-app-maven", 29 "joda-time", 30 }, 31 }, 32 } 33 for _, test := range tests { 34 t.Run(path.Base(test.fixture), func(t *testing.T) { 35 generateJavaBuildFixture(t, test.fixture) 36 37 fixture, err := os.Open(test.fixture) 38 if err != nil { 39 t.Fatalf("failed to open fixture: %+v", err) 40 } 41 42 actualPkgs, _, err := parseTarWrappedJavaArchive(nil, nil, file.LocationReadCloser{ 43 Location: file.NewLocation(test.fixture), 44 ReadCloser: fixture, 45 }) 46 require.NoError(t, err) 47 48 var actualNames []string 49 for _, p := range actualPkgs { 50 actualNames = append(actualNames, p.Name) 51 } 52 53 assert.ElementsMatch(t, test.expected, actualNames) 54 }) 55 } 56 }