github.com/nextlinux/gosbom@v0.81.1-0.20230627115839-1ff50c281391/gosbom/pkg/cataloger/java/parse_pom_properties_test.go (about)

     1  package java
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  
     7  	"github.com/nextlinux/gosbom/gosbom/pkg"
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  func TestParseJavaPomProperties(t *testing.T) {
    12  	tests := []struct {
    13  		expected pkg.PomProperties
    14  	}{
    15  		{
    16  			expected: pkg.PomProperties{
    17  				Path:       "test-fixtures/pom/small.pom.properties",
    18  				GroupID:    "org.anchore",
    19  				ArtifactID: "example-java-app-maven",
    20  				Version:    "0.1.0",
    21  			},
    22  		},
    23  		{
    24  			expected: pkg.PomProperties{
    25  				Path:       "test-fixtures/pom/extra.pom.properties",
    26  				GroupID:    "org.anchore",
    27  				ArtifactID: "example-java-app-maven",
    28  				Version:    "0.1.0",
    29  				Name:       "something-here",
    30  				Extra: map[string]string{
    31  					"another": "thing",
    32  					"sweet":   "work",
    33  				},
    34  			},
    35  		},
    36  		{
    37  			expected: pkg.PomProperties{
    38  				Path:       "test-fixtures/pom/colon-delimited.pom.properties",
    39  				GroupID:    "org.anchore",
    40  				ArtifactID: "example-java-app-maven",
    41  				Version:    "0.1.0",
    42  			},
    43  		},
    44  		{
    45  			expected: pkg.PomProperties{
    46  				Path:       "test-fixtures/pom/equals-delimited-with-colons.pom.properties",
    47  				GroupID:    "org.anchore",
    48  				ArtifactID: "example-java:app-maven",
    49  				Version:    "0.1.0:something",
    50  			},
    51  		},
    52  		{
    53  			expected: pkg.PomProperties{
    54  				Path:       "test-fixtures/pom/colon-delimited-with-equals.pom.properties",
    55  				GroupID:    "org.anchore",
    56  				ArtifactID: "example-java=app-maven",
    57  				Version:    "0.1.0=something",
    58  			},
    59  		},
    60  	}
    61  
    62  	for _, test := range tests {
    63  		t.Run(test.expected.Path, func(t *testing.T) {
    64  			fixture, err := os.Open(test.expected.Path)
    65  			assert.NoError(t, err)
    66  
    67  			actual, err := parsePomProperties(fixture.Name(), fixture)
    68  			assert.NoError(t, err)
    69  
    70  			assert.Equal(t, &test.expected, actual)
    71  		})
    72  	}
    73  }