fix: maven fallback to parent groupId

This commit is contained in:
Julian Schlarb 2024-12-19 12:30:06 +01:00
parent 248977c518
commit b15352ceb0
2 changed files with 60 additions and 1 deletions

View file

@ -14,6 +14,7 @@ import (
const (
groupID = "org.gitea"
parentGroupID = "org.gitea.parent"
artifactID = "my-project"
version = "1.0.1"
name = "My Gitea Project"
@ -27,6 +28,11 @@ const (
const pomContent = `<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>` + parentGroupID + `</groupId>
<artifactId>parent-project</artifactId>
<version>1.0.0</version>
</parent>
<groupId>` + groupID + `</groupId>
<artifactId>` + artifactID + `</artifactId>
<version>` + version + `</version>
@ -47,6 +53,24 @@ const pomContent = `<?xml version="1.0"?>
</dependencies>
</project>`
const pomWithParentGroupID = `<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>` + parentGroupID + `</groupId>
<artifactId>parent-project</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>` + artifactID + `</artifactId>
<version>` + version + `</version>
</project>`
const pomWithMissingGroupID = `<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<artifactId>` + artifactID + `</artifactId>
<version>` + version + `</version>
</project>`
func TestParsePackageMetaData(t *testing.T) {
t.Run("InvalidFile", func(t *testing.T) {
m, err := ParsePackageMetaData(strings.NewReader(""))
@ -87,4 +111,19 @@ func TestParsePackageMetaData(t *testing.T) {
require.NoError(t, err)
assert.NotNil(t, m)
})
t.Run("UseParentGroupID", func(t *testing.T) {
m, err := ParsePackageMetaData(strings.NewReader(pomWithParentGroupID))
require.NoError(t, err)
assert.NotNil(t, m)
assert.Equal(t, parentGroupID, m.GroupID)
})
t.Run("MissingGroupIDThrowsError", func(t *testing.T) {
m, err := ParsePackageMetaData(strings.NewReader(pomWithMissingGroupID))
assert.Nil(t, m)
require.Error(t, err)
assert.Equal(t, ErrNoGroupID, err)
})
}