1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00

fix(fortify): project version fetch bug (#3854)

Fixed the filter for projectversion GET call
This commit is contained in:
Vinayak S 2022-06-27 18:13:57 +05:30 committed by GitHub
parent 9af9a2418d
commit b25f596af5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 5 deletions

View File

@ -197,17 +197,17 @@ func (sys *SystemInstance) GetProjectByName(projectName string, autoCreate bool,
// GetProjectVersionDetailsByProjectIDAndVersionName returns the project version details of the project version identified by the id and project versionname
// projectName parameter is only used if autoCreate=true
func (sys *SystemInstance) GetProjectVersionDetailsByProjectIDAndVersionName(id int64, versionName string, autoCreate bool, projectName string) (*models.ProjectVersion, error) {
nameParam := fmt.Sprintf("name=%v", versionName)
nameParam := fmt.Sprintf("name:%v", versionName)
params := &project_version_of_project_controller.ListProjectVersionOfProjectParams{ParentID: id, Q: &nameParam}
params.WithTimeout(sys.timeout)
result, err := sys.client.ProjectVersionOfProjectController.ListProjectVersionOfProject(params, sys)
if err != nil {
return nil, err
}
for _, projectVersion := range result.GetPayload().Data {
if *projectVersion.Name == versionName {
return projectVersion, nil
}
if result.Payload.Count > 0 {
projectVersion := result.GetPayload().Data[0]
return projectVersion, nil
}
// projectVersion not found for specified project id and name, check if autoCreate is enabled
if !autoCreate {

View File

@ -259,6 +259,21 @@ func TestGetProjectVersionDetailsByProjectIDAndVersionName(t *testing.T) {
"first":{"href":"https://fortify/ssc/api/v1/projects/815/versions?start=0"}}}`))
return
}
if req.URL.Path == "/projects/8888/versions" && req.URL.RawQuery == "q=name%3A1" {
header := rw.Header()
header.Add("Content-type", "application/json")
rw.Write([]byte(`{"data":[{"id":9910,"project":{"id":8888,"name":"test","description":"Created by Go script","creationDate":"2022-06-24T04:44:12.344+0000",
"createdBy":"jajajajja","issueTemplateId":"asxasca-asff-b57aedaf41"},"name":"1","description":"","createdBy":"afsafa","creationDate":"2021-07-17T04:09:17.909+0000",
"sourceBasePath":null,"committed":true,"issueTemplateId":"asdawffbcad88eb041","issueTemplateName":"aiudfnwofn","loadProperties":null,"staleIssueTemplate":false,
"snapshotOutOfDate":false,"refreshRequired":false,"attachmentsOutOfDate":false,"migrationVersion":null,"masterAttrGuid":"akjnfkjsnfkj686b","tracesOutOfDate":false,
"issueTemplateModifiedTime":1556502937909,"active":true,"obfuscatedId":null,"owner":"","serverVersion":21.2,"siteId":null,"latestScanId":null,"mode":"BASIC",
"currentState":{"id":9910,"committed":true,"attentionRequired":false,"analysisResultsExist":false,"auditEnabled":false,"lastFprUploadDate":null,"extraMessage":null,
"analysisUploadEnabled":true,"batchBugSubmissionExists":false,"hasCustomIssues":false,"metricEvaluationDate":null,"deltaPeriod":7,"issueCountDelta":0,"percentAuditedDelta":0,
"criticalPriorityIssueCountDelta":0,"percentCriticalPriorityIssuesAuditedDelta":0},"bugTrackerPluginId":null,"bugTrackerEnabled":false,"securityGroup":null,"status":null,
"assignedIssuesCount":0,"customTagValuesAutoApply":null,"autoPredict":null,"predictionPolicy":null,"_href":"https://fortify/ssc/api/v1/projectVersions/8888"}],"count":1,
"responseCode":200,"links":{"last":{"href":"https://fortify/ssc/api/v1/projects/8888/versions?q=name%3A1&start=0"},"first":{"href":"https://fortify/ssc/api/v1/projects/8888/versions?q=name%3A1&start=0"}}}`))
return
}
})
// Close the server when test finishes
@ -286,6 +301,11 @@ func TestGetProjectVersionDetailsByProjectIDAndVersionName(t *testing.T) {
assert.Equal(t, "0", *result.Name, "Expected to get project version with different name")
assert.Equal(t, "autocreate", *result.Project.Name, "Expected to get project with different name")
})
t.Run("test filter projectVersion", func(t *testing.T) {
result, err := sys.GetProjectVersionDetailsByProjectIDAndVersionName(8888, "1", true, "autocreate")
assert.NoError(t, err, "GetProjectVersionDetailsByNameAndProjectID call not successful")
assert.Equal(t, "1", *result.Name, "Expected to get exact project version")
})
}
func TestGetProjectVersionAttributesByProjectVersionID(t *testing.T) {