github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/packages/maven/metadata_test.go (about) 1 // Copyright 2023 The GitBundle Inc. All rights reserved. 2 // Copyright 2017 The Gitea Authors. All rights reserved. 3 // Use of this source code is governed by a MIT-style 4 // license that can be found in the LICENSE file. 5 6 package maven 7 8 import ( 9 "strings" 10 "testing" 11 12 "github.com/stretchr/testify/assert" 13 ) 14 15 const ( 16 groupID = "org.gitbundle" 17 artifactID = "my-project" 18 version = "1.0.1" 19 name = "My GitBundle Project" 20 description = "Package Description" 21 projectURL = "https://gitbundle.com" 22 license = "MIT" 23 dependencyGroupID = "org.gitbundle.core" 24 dependencyArtifactID = "git" 25 dependencyVersion = "5.0.0" 26 ) 27 28 const pomContent = `<?xml version="1.0"?> 29 <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 30 <groupId>` + groupID + `</groupId> 31 <artifactId>` + artifactID + `</artifactId> 32 <version>` + version + `</version> 33 <name>` + name + `</name> 34 <description>` + description + `</description> 35 <url>` + projectURL + `</url> 36 <licenses> 37 <license> 38 <name>` + license + `</name> 39 </license> 40 </licenses> 41 <dependencies> 42 <dependency> 43 <groupId>` + dependencyGroupID + `</groupId> 44 <artifactId>` + dependencyArtifactID + `</artifactId> 45 <version>` + dependencyVersion + `</version> 46 </dependency> 47 </dependencies> 48 </project>` 49 50 func TestParsePackageMetaData(t *testing.T) { 51 t.Run("InvalidFile", func(t *testing.T) { 52 m, err := ParsePackageMetaData(strings.NewReader("")) 53 assert.Nil(t, m) 54 assert.Error(t, err) 55 }) 56 57 t.Run("Valid", func(t *testing.T) { 58 m, err := ParsePackageMetaData(strings.NewReader(pomContent)) 59 assert.NoError(t, err) 60 assert.NotNil(t, m) 61 62 assert.Equal(t, groupID, m.GroupID) 63 assert.Equal(t, artifactID, m.ArtifactID) 64 assert.Equal(t, name, m.Name) 65 assert.Equal(t, description, m.Description) 66 assert.Equal(t, projectURL, m.ProjectURL) 67 assert.Len(t, m.Licenses, 1) 68 assert.Equal(t, license, m.Licenses[0]) 69 assert.Len(t, m.Dependencies, 1) 70 assert.Equal(t, dependencyGroupID, m.Dependencies[0].GroupID) 71 assert.Equal(t, dependencyArtifactID, m.Dependencies[0].ArtifactID) 72 assert.Equal(t, dependencyVersion, m.Dependencies[0].Version) 73 }) 74 }