Skip to content

Commit 44a20d6

Browse files
dotkasPeterSchafer
andauthored
fix: add project and snapshot as resultmetadata
Co-authored-by: PeterSchafer <[email protected]>
1 parent 16e5334 commit 44a20d6

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

internal/analysis/analysis.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,19 @@ func (a *analysisOrchestrator) retrieveTestURL(ctx context.Context, client *test
344344
result := &scan.ResultMetaData{
345345
FindingsUrl: findingsUrl,
346346
}
347-
if testCompleted.Results.Webui != nil && testCompleted.Results.Webui.Link != nil {
348-
result.WebUiUrl = *testCompleted.Results.Webui.Link
347+
348+
if testCompleted.Results.Webui != nil {
349+
if testCompleted.Results.Webui.Link != nil {
350+
result.WebUiUrl = *testCompleted.Results.Webui.Link
351+
}
352+
if testCompleted.Results.Webui.ProjectId != nil {
353+
result.ProjectId = testCompleted.Results.Webui.ProjectId.String()
354+
}
355+
if testCompleted.Results.Webui.SnapshotId != nil {
356+
result.SnapshotId = testCompleted.Results.Webui.SnapshotId.String()
357+
}
349358
}
359+
350360
return result, true, nil
351361
default:
352362
return nil, false, fmt.Errorf("unexpected test status \"%s\"", stateDiscriminator)

internal/analysis/analysis_test.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,14 @@ func mockGetDocumentResponse(t *testing.T, sarifResponse sarif.SarifDocument, ex
6868
}, mockDeriveErrorFromStatusCode(responseCode))
6969
}
7070

71-
func mockResultCompletedResponse(t *testing.T, mockHTTPClient *httpmocks.MockHTTPClient, expectedWebuilink string, projectId uuid.UUID, orgId string, testId uuid.UUID, documentPath string, responseCode int) {
71+
func mockResultCompletedResponse(t *testing.T, mockHTTPClient *httpmocks.MockHTTPClient, expectedWebuilink string, projectId uuid.UUID, snapshotId uuid.UUID, orgId string, testId uuid.UUID, documentPath string, responseCode int) {
7272
t.Helper()
7373
response := v20241221.NewTestResponse()
7474
state := v20241221.NewTestCompleteState()
7575
state.Documents.EnrichedSarif = documentPath
7676
state.Results.Webui.Link = &expectedWebuilink
7777
state.Results.Webui.ProjectId = &projectId
78+
state.Results.Webui.SnapshotId = &snapshotId
7879
stateBytes, err := json.Marshal(state)
7980
assert.NoError(t, err)
8081
response.Data.Attributes.UnmarshalJSON(stateBytes)
@@ -150,6 +151,7 @@ func TestAnalysis_RunTest(t *testing.T) {
150151

151152
orgId := "4a72d1db-b465-4764-99e1-ecedad03b06a"
152153
projectId := uuid.New()
154+
snapshotId := uuid.New()
153155
testId := uuid.New()
154156
report := true
155157
inputBundle := mocks2.NewMockBundle(ctrl)
@@ -165,7 +167,7 @@ func TestAnalysis_RunTest(t *testing.T) {
165167
// Get Test Result Response
166168
expectedWebuilink := ""
167169
expectedDocumentPath := "/1234"
168-
mockResultCompletedResponse(t, mockHTTPClient, expectedWebuilink, projectId, orgId, testId, expectedDocumentPath, http.StatusOK)
170+
mockResultCompletedResponse(t, mockHTTPClient, expectedWebuilink, projectId, snapshotId, orgId, testId, expectedDocumentPath, http.StatusOK)
169171

170172
// get document
171173
sarifResponse := sarif.SarifDocument{
@@ -197,6 +199,8 @@ func TestAnalysis_RunTest(t *testing.T) {
197199
assert.NotNil(t, result)
198200
assert.NotNil(t, resultMetadata)
199201
assert.Equal(t, expectedWebuilink, resultMetadata.WebUiUrl)
202+
assert.Equal(t, projectId.String(), resultMetadata.ProjectId)
203+
assert.Equal(t, snapshotId.String(), resultMetadata.SnapshotId)
200204
assert.Equal(t, sarifResponse.Version, result.Sarif.Version)
201205
}
202206

@@ -207,6 +211,7 @@ func TestAnalysis_RunTestRemote(t *testing.T) {
207211

208212
orgId := "4a72d1db-b465-4764-99e1-ecedad03b06a"
209213
projectId := uuid.New()
214+
snapshotId := uuid.New()
210215
testId := uuid.New()
211216
commitId := "abc123"
212217
report := true
@@ -217,7 +222,7 @@ func TestAnalysis_RunTestRemote(t *testing.T) {
217222
// Get Test Result Response
218223
expectedWebuilink := ""
219224
expectedDocumentPath := "/1234"
220-
mockResultCompletedResponse(t, mockHTTPClient, expectedWebuilink, projectId, orgId, testId, expectedDocumentPath, http.StatusOK)
225+
mockResultCompletedResponse(t, mockHTTPClient, expectedWebuilink, projectId, snapshotId, orgId, testId, expectedDocumentPath, http.StatusOK)
221226

222227
// get document
223228
sarifResponse := sarif.SarifDocument{
@@ -249,6 +254,8 @@ func TestAnalysis_RunTestRemote(t *testing.T) {
249254
assert.NotNil(t, result)
250255
assert.NotNil(t, resultMetadata)
251256
assert.Equal(t, expectedWebuilink, resultMetadata.WebUiUrl)
257+
assert.Equal(t, projectId.String(), resultMetadata.ProjectId)
258+
assert.Equal(t, snapshotId.String(), resultMetadata.SnapshotId)
252259
assert.Equal(t, sarifResponse.Version, result.Sarif.Version)
253260
}
254261

@@ -308,7 +315,7 @@ func TestAnalysis_RunTestRemote_PollingFailed(t *testing.T) {
308315
// Get Test Result Response
309316
expectedWebuilink := ""
310317
expectedDocumentPath := "/1234"
311-
mockResultCompletedResponse(t, mockHTTPClient, expectedWebuilink, projectId, orgId, testId, expectedDocumentPath, http.StatusInternalServerError)
318+
mockResultCompletedResponse(t, mockHTTPClient, expectedWebuilink, projectId, uuid.New(), orgId, testId, expectedDocumentPath, http.StatusInternalServerError)
312319

313320
analysisOrchestrator := analysis.NewAnalysisOrchestrator(
314321
mockConfig,
@@ -352,7 +359,7 @@ func TestAnalysis_RunTestRemote_GetDocumentFailed(t *testing.T) {
352359
// Get Test Result Response
353360
expectedWebuilink := ""
354361
expectedDocumentPath := "/1234"
355-
mockResultCompletedResponse(t, mockHTTPClient, expectedWebuilink, projectId, orgId, testId, expectedDocumentPath, http.StatusOK)
362+
mockResultCompletedResponse(t, mockHTTPClient, expectedWebuilink, projectId, uuid.New(), orgId, testId, expectedDocumentPath, http.StatusOK)
356363

357364
// get document
358365
sarifResponse := sarif.SarifDocument{

sarif/sarif_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ type RunProperties struct {
179179
Lang string `json:"lang"`
180180
Type string `json:"type"`
181181
} `json:"coverage"`
182+
UploadResult struct {
183+
ProjectId string `json:"projectId"`
184+
SnapshotId string `json:"snapshotId"`
185+
ReportUrl string `json:"reportUrl"`
186+
} `json:"uploadResult,omitempty"`
182187
}
183188

184189
type Run struct {

scan/scan_metadata.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import "context"
55
type ResultMetaData struct {
66
FindingsUrl string
77
WebUiUrl string
8+
ProjectId string
9+
SnapshotId string
810
}
911

1012
type ScanSource string

0 commit comments

Comments
 (0)