-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4f9ea92
commit ddd500f
Showing
3 changed files
with
48 additions
and
8 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
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 |
---|---|---|
@@ -1,15 +1,52 @@ | ||
const taskAutoscaleWeb = require('../../../../run/services/task-autoscale-web'); | ||
const { expect, sinon } = require('../../../test-helper'); | ||
const { expect, sinon, catchErr } = require('../../../test-helper'); | ||
|
||
describe('#task-autoscale-web', function () { | ||
it('should call autoscale on web container for specified application', async function () { | ||
// given | ||
const applicationName = 'pix-api-test'; | ||
const region = 'recette'; | ||
const autoScalingParameters = { min: 2, max: 4 }; | ||
|
||
const scalingoClientStub = sinon.stub(); | ||
const autoScalerStub = sinon.stub(); | ||
const updateAutoscalerStub = sinon.stub(); | ||
|
||
const getInstanceStub = sinon.stub().resolves({ | ||
updateAutoscaler: updateAutoscalerStub, | ||
}); | ||
scalingoClientStub.getInstance = getInstanceStub; | ||
|
||
// when | ||
await taskAutoscaleWeb.run({ applicationName, region, autoScalingParameters }, scalingoClientStub); | ||
|
||
// then | ||
expect(getInstanceStub.calledOnceWithExactly(region)).to.be.true; | ||
expect(updateAutoscalerStub.calledOnceWithExactly(applicationName, autoScalingParameters)).to.be.true; | ||
}); | ||
it('should throw an error on scalingo errors', async function () { | ||
// given | ||
const applicationName = 'pix-api-test'; | ||
const region = 'recette'; | ||
const autoScalingParameters = { min: 2, max: 4 }; | ||
|
||
const scalingoClientStub = sinon.stub(); | ||
const updateAutoscalerStub = sinon.stub().rejects(new Error('Cannot configure autoscaler')); | ||
|
||
const getInstanceStub = sinon.stub().resolves({ | ||
updateAutoscaler: updateAutoscalerStub, | ||
}); | ||
|
||
scalingoClientStub.getInstance = getInstanceStub; | ||
|
||
// when | ||
await taskAutoscaleWeb.run(scalingoClientStub); | ||
const result = await catchErr(taskAutoscaleWeb.run)( | ||
{ applicationName, region, autoScalingParameters }, | ||
scalingoClientStub, | ||
); | ||
|
||
// then | ||
expect(autoScalerStub.called).to.be.true; | ||
expect(getInstanceStub.calledOnceWithExactly(region)).to.be.true; | ||
expect(result).to.be.instanceOf(Error); | ||
expect(result.message).to.be.equal('Scalingo APIError: Cannot configure autoscaler'); | ||
}); | ||
}); |