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
Jk1484 ffc931aad1
feat(golangBuild): use 'unit' build tag to include tests during test execution (#4345)
* Added unit tag as argument. Added description to runTests command. Changed code generator to have unit build tag in generated unit test files.

* Added unit build tag to all unit test files.

* added to new unit test unit build tag

* Update verify-go.yml

* small fix

---------

Co-authored-by: Muhammadali Nazarov <Muhammadali.Nazarov@acronis.com>
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2023-05-03 21:02:11 +05:00

69 lines
1.9 KiB
Go

//go:build unit
// +build unit
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")
})
}