Skip to content

Commit

Permalink
added test for nuget multi project without restore
Browse files Browse the repository at this point in the history
  • Loading branch information
eranturgeman committed Sep 6, 2023
1 parent ca3a1f3 commit 2397954
Showing 1 changed file with 33 additions and 7 deletions.
40 changes: 33 additions & 7 deletions xray_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,22 +212,46 @@ func runXrayAuditYarnWithOutput(t *testing.T, format string) string {

// Tests NuGet audit by providing simple NuGet project and asserts any error.
func TestXrayAuditNugetJson(t *testing.T) {
output := testXrayAuditNuget(t, "single", string(utils.Json))
output := testXrayAuditNuget(t, "single", string(utils.Json), true, "nuget")
verifyJsonScanResults(t, output, 0, 2, 0)
}

func TestXrayAuditNugetSimpleJson(t *testing.T) {
output := testXrayAuditNuget(t, "single", string(utils.SimpleJson))
output := testXrayAuditNuget(t, "single", string(utils.SimpleJson), true, "nuget")
verifySimpleJsonScanResults(t, output, 2, 0)
}

// Tests NuGet audit by providing a multi-project NuGet project and asserts any error.
func TestXrayAuditNugetMultiProject(t *testing.T) {
output := testXrayAuditNuget(t, "multi", string(utils.Json))
verifyJsonScanResults(t, output, 0, 5, 0)
var testdata = []struct {
projectName string
format string
runInstallCommand bool
restoreTech string
}{
{
projectName: "multi",
format: string(utils.Json),
runInstallCommand: true,
restoreTech: "dotnet",
},
{
projectName: "multi",
format: string(utils.Json),
runInstallCommand: false,
restoreTech: "",
},
}
for _, test := range testdata {
t.Run(fmt.Sprintf("Nuget multi project,runInstallCommand:%t", test.runInstallCommand),
func(t *testing.T) {
output := testXrayAuditNuget(t, test.projectName, test.format, test.runInstallCommand, test.restoreTech)
verifyJsonScanResults(t, output, 0, 5, 0)
})
}
}

func testXrayAuditNuget(t *testing.T, projectName, format string) string {
func testXrayAuditNuget(t *testing.T, projectName, format string, runInstallCommand bool, restoreTech string) string {
initXrayTest(t, scangraph.GraphScanMinXrayVersion)
tempDirPath, createTempDirCallback := coretests.CreateTempDirWithCallbackAndAssert(t)
defer createTempDirCallback()
Expand All @@ -239,8 +263,10 @@ func testXrayAuditNuget(t *testing.T, projectName, format string) string {
// Add dummy descriptor file to check that we run only specific audit
addDummyPackageDescriptor(t, false)
// Run NuGet restore before executing jfrog xr audit (NuGet)
_, err := exec.Command("nuget", "restore").CombinedOutput()
assert.NoError(t, err)
if runInstallCommand {
_, err := exec.Command(restoreTech, "restore").CombinedOutput()
assert.NoError(t, err)
}
return xrayCli.RunCliCmdWithOutput(t, "audit", "--nuget", "--format="+format)
}

Expand Down

0 comments on commit 2397954

Please sign in to comment.