Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print detailed url also when queue time is long #251

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion internal/scan/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ func (dScanner *DebrickedScanner) Scan(o IOptions) error {
return dScanner.handleScanError(err, dOptions.PassOnTimeOut)
}

if result == nil {
if result.LongQueue {
fmt.Println("Progress polling terminated due to long scan times. Please try again later")
fmt.Printf("For full details, visit: %s\n\n", color.BlueString(result.DetailsUrl))

return nil
}
Expand Down
15 changes: 14 additions & 1 deletion internal/scan/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func TestScanEmptyResult(t *testing.T) {
addMockedFinishResponse(clientMock, http.StatusNoContent)
addMockedStatusResponse(clientMock, http.StatusOK, 50)
// Create mocked scan result response, 201 is returned when the queue time are too long
addMockedStatusResponse(clientMock, http.StatusCreated, 0)
addMockedQueueTooLongStatusResponse(clientMock)

scanner := makeScanner(clientMock, nil, nil)
path := testdataNpm
Expand Down Expand Up @@ -297,6 +297,11 @@ func TestScanEmptyResult(t *testing.T) {

assert.NoError(t, err, "failed to assert that scan ran without errors")
assert.True(t, existsMessageInCMDOutput, "failed to assert that scan ran without errors")

existsMessageInCMDOutputDetails := strings.Contains(
string(out),
"http://localhost:8888/app/en/repository/13/commit/37")
assert.True(t, existsMessageInCMDOutputDetails, "failed to assert that long queue scan contain detailed url")
}

func TestScanInCiWithPathSet(t *testing.T) {
Expand Down Expand Up @@ -789,6 +794,14 @@ func addMockedStatusResponse(clientMock *testdata.DebClientMock, statusCode int,
clientMock.AddMockUriResponse("/api/1.0/open/ci/upload/status", finishMockRes)
}

func addMockedQueueTooLongStatusResponse(clientMock *testdata.DebClientMock) {
finishMockRes := testdata.MockResponse{
StatusCode: http.StatusCreated,
ResponseBody: io.NopCloser(strings.NewReader(`{"message": "Queue too long","detailsUrl":"http://localhost:8888/app/en/repository/13/commit/37"}`)),
}
clientMock.AddMockUriResponse("/api/1.0/open/ci/upload/status", finishMockRes)
}

func resetWd(t *testing.T, wd string) {
err := os.Chdir(wd)
if err != nil {
Expand Down
13 changes: 9 additions & 4 deletions internal/upload/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,18 +224,23 @@ func (uploadBatch *uploadBatch) wait() (*UploadResult, error) {
if err != nil {
return nil, err
}
status, err := newUploadStatus(res)
if err != nil {
return nil, err
}
if res.StatusCode == http.StatusCreated {
err := bar.Finish()
if err != nil {
return resultStatus, err
}

resultStatus = &UploadResult{
DetailsUrl: status.DetailsUrl,
LongQueue: true,
}

return resultStatus, PollingTerminatedErr
}
status, err := newUploadStatus(res)
if err != nil {
return nil, err
}
err = bar.Set(status.Progress)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion internal/upload/batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestWaitWithPollingTerminatedError(t *testing.T) {

uploadResult, err := batch.wait()

assert.Nil(t, uploadResult)
assert.True(t, uploadResult.LongQueue)
assert.ErrorIs(t, err, PollingTerminatedErr)
}

Expand Down
2 changes: 2 additions & 0 deletions internal/upload/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type UploadResult struct {
AutomationsAction string `json:"automationsAction"`
AutomationRules []automation.Rule `json:"automationRules"`
DetailsUrl string `json:"detailsUrl"`
LongQueue bool
}

func newUploadResult(status *uploadStatus) *UploadResult {
Expand All @@ -19,5 +20,6 @@ func newUploadResult(status *uploadStatus) *UploadResult {
status.AutomationsAction,
status.AutomationRules,
status.DetailsUrl,
false,
}
}
2 changes: 1 addition & 1 deletion internal/upload/uploader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestUploadPollingError(t *testing.T) {
result, err := uploader.Upload(uploaderOptions)

assert.NoError(t, err)
assert.Nil(t, result)
assert.True(t, result.LongQueue)
}

type debClientMock struct{}
Expand Down