-
Notifications
You must be signed in to change notification settings - Fork 563
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Carlos <carlos@snyk.io> Cu-authored-by: Lucian <lucian.rosu@snyk.io>
- Loading branch information
Showing
11 changed files
with
167 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { CustomError } from './custom-error'; | ||
|
||
export class BadGatewayError extends CustomError { | ||
private static ERROR_CODE = 502; | ||
private static ERROR_STRING_CODE = 'BAD_GATEWAY_ERROR'; | ||
private static ERROR_MESSAGE = 'Bad gateway error'; | ||
|
||
constructor(userMessage) { | ||
super(BadGatewayError.ERROR_MESSAGE); | ||
this.code = BadGatewayError.ERROR_CODE; | ||
this.strCode = BadGatewayError.ERROR_STRING_CODE; | ||
this.userMessage = userMessage || BadGatewayError.ERROR_MESSAGE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { CustomError } from './custom-error'; | ||
|
||
export class ServiceUnavailableError extends CustomError { | ||
private static ERROR_CODE = 503; | ||
private static ERROR_STRING_CODE = 'SERVICE_UNAVAILABLE_ERROR'; | ||
private static ERROR_MESSAGE = 'Service unavailable error'; | ||
|
||
constructor(userMessage) { | ||
super(ServiceUnavailableError.ERROR_MESSAGE); | ||
this.code = ServiceUnavailableError.ERROR_CODE; | ||
this.strCode = ServiceUnavailableError.ERROR_STRING_CODE; | ||
this.userMessage = userMessage || ServiceUnavailableError.ERROR_MESSAGE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { fakeServer } from '../../../acceptance/fake-server'; | ||
import { createProjectFromWorkspace } from '../../util/createProject'; | ||
import { runSnykCLI } from '../../util/runSnykCLI'; | ||
import { RETRY_ATTEMPTS } from '../../../../src/lib/snyk-test/common'; | ||
|
||
jest.setTimeout(2000 * 60); | ||
|
||
describe('snyk test retry mechanism', () => { | ||
let server; | ||
let env: Record<string, string>; | ||
|
||
beforeAll((done) => { | ||
const port = process.env.PORT || process.env.SNYK_PORT || '12345'; | ||
const baseApi = '/api/v1'; | ||
env = { | ||
...process.env, | ||
SNYK_API: 'http://localhost:' + port + baseApi, | ||
SNYK_HOST: 'http://localhost:' + port, | ||
SNYK_TOKEN: '123456789', | ||
SNYK_DISABLE_ANALYTICS: '1', | ||
}; | ||
server = fakeServer(baseApi, env.SNYK_TOKEN); | ||
server.listen(port, () => { | ||
done(); | ||
}); | ||
}); | ||
|
||
afterAll((done) => { | ||
server.close(() => { | ||
done(); | ||
}); | ||
}); | ||
|
||
test('run `snyk test` on an arbitrary cocoapods project and expect retries in case of failures', async () => { | ||
const project = await createProjectFromWorkspace('cocoapods-app'); | ||
const statuses = Array(RETRY_ATTEMPTS - 1) | ||
.fill(500) | ||
.concat([200]); | ||
server.setStatusCodes(statuses); | ||
|
||
const { code } = await runSnykCLI('test', { | ||
cwd: project.path(), | ||
env, | ||
}); | ||
|
||
expect(code).toEqual(0); | ||
}); | ||
|
||
test('run `snyk test` on an arbitrary cocoapods project and expect failure when the retry budget is consumed', async () => { | ||
const project = await createProjectFromWorkspace('cocoapods-app'); | ||
server.setStatusCodes(Array(RETRY_ATTEMPTS).fill(500)); | ||
|
||
const { code } = await runSnykCLI('test', { | ||
cwd: project.path(), | ||
env, | ||
}); | ||
|
||
expect(code).toEqual(2); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters