-
Notifications
You must be signed in to change notification settings - Fork 594
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add build artifacts metadata for mtaBuild (#5166)
- Loading branch information
1 parent
da609e1
commit 6988f43
Showing
10 changed files
with
395 additions
and
300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,18 +4,14 @@ | |
package cmd | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/SAP/jenkins-library/pkg/piperutils" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var cpe mavenBuildCommonPipelineEnvironment | ||
|
||
func TestMavenBuild(t *testing.T) { | ||
|
||
t.Run("mavenBuild should install the artifact", func(t *testing.T) { | ||
mockedUtils := newMavenMockUtils() | ||
|
||
|
@@ -123,54 +119,4 @@ func TestMavenBuild(t *testing.T) { | |
assert.Equal(t, mockedUtils.Calls[0].Exec, "mvn") | ||
assert.Empty(t, cpe.custom.mavenBuildArtifacts) | ||
}) | ||
|
||
} | ||
|
||
func createTempFile(t *testing.T, dir string, filename string, content string) string { | ||
filePath := filepath.Join(dir, filename) | ||
err := os.WriteFile(filePath, []byte(content), 0666) | ||
if err != nil { | ||
t.Fatalf("Failed to create temp file: %s", err) | ||
} | ||
return filePath | ||
} | ||
|
||
func TestGetPurlForThePomAndDeleteIndividualBom(t *testing.T) { | ||
|
||
t.Run("valid BOM file, aggregated BOM", func(t *testing.T) { | ||
tempDir, err := piperutils.Files{}.TempDir("", "test") | ||
if err != nil { | ||
t.Fatalf("Failed to create temp directory: %s", err) | ||
} | ||
|
||
bomContent := `<bom> | ||
<metadata> | ||
<component> | ||
<purl>pkg:maven/com.example/[email protected]</purl> | ||
</component> | ||
<properties> | ||
<property name="maven.goal" value="makeAggregateBom" /> | ||
</properties> | ||
</metadata> | ||
</bom>` | ||
pomFilePath := createTempFile(t, tempDir, "pom.xml", "") | ||
bomDir := filepath.Join(tempDir, "target") | ||
if err := os.MkdirAll(bomDir, 0777); err != nil { | ||
t.Fatalf("Failed to create temp directory: %s", err) | ||
} | ||
bomFilePath := createTempFile(t, bomDir, mvnSimpleBomFilename+".xml", bomContent) | ||
|
||
purl := getPurlForThePom(pomFilePath) | ||
assert.Equal(t, "pkg:maven/com.example/[email protected]", purl) | ||
_, err = os.Stat(bomFilePath) | ||
assert.False(t, os.IsNotExist(err)) // File should not be deleted | ||
}) | ||
|
||
t.Run("BOM file does not exist", func(t *testing.T) { | ||
tempDir := t.TempDir() | ||
pomFilePath := createTempFile(t, tempDir, "pom.xml", "") // Create a temp pom file | ||
|
||
purl := getPurlForThePom(pomFilePath) | ||
assert.Equal(t, "", purl) | ||
}) | ||
} |
Oops, something went wrong.