Skip to content

Commit 2e0158f

Browse files
Added additional test cases for coverage
1 parent 753d221 commit 2e0158f

File tree

2 files changed

+50
-18
lines changed

2 files changed

+50
-18
lines changed

test/integration/predicate_test.go

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -214,32 +214,49 @@ func TestSastUpdateAndGetPredicatesForNotFoundSimilarityId(t *testing.T) {
214214
}
215215

216216
func TestTriageShowAndUpdateWithCustomStates(t *testing.T) {
217-
t.Skip("Skipping this test temporarily until the API becomes available in the DEU environment.")
218217
fmt.Println("Step 1: Testing the command 'triage show' with predefined values.")
219218
// After the api/custom-states becomes available in the DEU environment, replace the hardcoded value with getRootScan(t) and create "state2" as a custom state in DEU.
220-
projectID := "a2d52ac9-d007-4d95-a65e-bbe61c3451a4"
221-
similarityID := "-1213859962"
222-
scanType := "sast"
223-
224-
outputBuffer := executeCmdNilAssertion(
225-
t, "Fetching predicates should work.", "triage", "show",
226-
flag(params.FormatFlag), printer.FormatJSON,
227-
flag(params.ProjectIDFlag), projectID,
228-
flag(params.SimilarityIDFlag), similarityID,
229-
flag(params.ScanTypeFlag), scanType,
219+
scanID, projectID := getRootScan(t)
220+
_ = executeCmdNilAssertion(
221+
t, "Results show generating JSON report with options should pass",
222+
"results", "show",
223+
flag(params.ScanIDFlag), scanID, flag(params.TargetFormatFlag), printer.FormatJSON,
224+
flag(params.TargetPathFlag), resultsDirectory,
225+
flag(params.TargetFlag), fileName,
230226
)
231227

232-
predicateResult := []wrappers.Predicate{}
233-
fmt.Println(outputBuffer)
234-
_ = unmarshall(t, outputBuffer, &predicateResult, "Reading results should pass")
235-
assert.Assert(t, len(predicateResult) >= 1, "Should have at least 1 predicate as the result.")
228+
defer func() {
229+
_ = os.RemoveAll(fmt.Sprintf(resultsDirectory))
230+
}()
231+
232+
result := wrappers.ScanResultsCollection{}
233+
234+
_, err := os.Stat(fmt.Sprintf("%s%s.%s", resultsDirectory, fileName, printer.FormatJSON))
235+
assert.NilError(t, err, "Report file should exist for extension "+printer.FormatJSON)
236+
237+
file, err := os.ReadFile(fmt.Sprintf("%s%s.%s", resultsDirectory, fileName, printer.FormatJSON))
238+
assert.NilError(t, err, "error reading file")
239+
240+
err = json.Unmarshal(file, &result)
241+
assert.NilError(t, err, "error unmarshalling file")
242+
243+
index := 0
244+
for i := range result.Results {
245+
if strings.EqualFold(result.Results[i].Type, params.SastType) {
246+
index = i
247+
break
248+
}
249+
}
250+
251+
similarityID := result.Results[index].SimilarityID
252+
scanType := result.Results[index].Type
236253

237254
fmt.Println("Step 2: Updating the predicate state.")
238-
newState := "state2"
255+
newState := "Custom1"
239256
newSeverity := "HIGH"
240-
comment := ""
257+
comment := "Updating State test"
241258

242-
err, _ := executeCommand(
259+
err, _ = executeCommand(
243260
t, "triage", "update",
244261
flag(params.ProjectIDFlag), projectID,
245262
flag(params.SimilarityIDFlag), similarityID,

test/integration/scan_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2710,3 +2710,18 @@ func TestCreateScanWithExistingProjectAnd_AssignApplication(t *testing.T) {
27102710
err, _ := executeCommand(t, args...)
27112711
assert.NilError(t, err, "Project should be assigned to application")
27122712
}
2713+
2714+
func TestCreateScanWithNewProjectName_Assign_Groups(t *testing.T) {
2715+
2716+
defer deleteProjectByName(t, getProjectNameForTest())
2717+
args := []string{
2718+
"scan", "create",
2719+
flag(params.ProjectName), getProjectNameForScanTests(),
2720+
flag(params.BranchFlag), "dummy_branch",
2721+
flag(params.SourcesFlag), "data/sources-gitignore.zip",
2722+
flag(params.ProjectGroupList), formatGroups(Groups),
2723+
}
2724+
err, _ := executeCommand(t, args...)
2725+
assert.NilError(t, err, "Groups should be assigned to newly created projects")
2726+
2727+
}

0 commit comments

Comments
 (0)