1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00
sap-jenkins-library/pkg/maven/model_test.go
Stephan Aßmus 54ea3ed51a
whitesourceExecuteScan: bypass UA for mta, maven, npm and yarn (#1879)
Co-authored-by: Florian Wilhelm <florian.wilhelm02@sap.com>
2020-09-29 12:44:31 +02:00

66 lines
1.9 KiB
Go

package maven
import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
)
const aggregatorPomXML = `<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>artifact</artifactId>
<groupId>group</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>project-aggregator</artifactId>
<packaging>pom</packaging>
<modules>
<module>sub1</module>
<module>sub2</module>
</modules>
</project>
`
func TestParsePOM(t *testing.T) {
t.Parallel()
t.Run("no XML data provided gives error", func(t *testing.T) {
project, err := ParsePOM(nil)
assert.EqualError(t, err, "failed to parse POM data: EOF")
assert.Nil(t, project)
})
t.Run("modules evaluated", func(t *testing.T) {
project, err := ParsePOM([]byte(aggregatorPomXML))
require.NoError(t, err)
require.NotNil(t, project)
require.Len(t, project.Modules, 2)
assert.Equal(t, project.Modules[0], "sub1")
assert.Equal(t, project.Modules[1], "sub2")
})
t.Run("artifact coordinates", func(t *testing.T) {
project, err := ParsePOM([]byte(aggregatorPomXML))
require.NoError(t, err)
require.NotNil(t, project)
assert.Equal(t, project.ArtifactID, "project-aggregator")
assert.Equal(t, project.Packaging, "pom")
})
t.Run("parent coordinates", func(t *testing.T) {
project, err := ParsePOM([]byte(aggregatorPomXML))
require.NoError(t, err)
require.NotNil(t, project)
assert.Equal(t, project.Parent.Version, "1.0-SNAPSHOT")
assert.Equal(t, project.Parent.GroupID, "group")
assert.Equal(t, project.Parent.ArtifactID, "artifact")
})
}