Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding greater than functionality to criteria, validation
- Loading branch information
Showing
4 changed files
with
171 additions
and
1 deletion.
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 |
---|---|---|
@@ -1,8 +1,23 @@ | ||
export class AverageResponseTime { | ||
|
||
lessThanTime: number; | ||
greaterThanTime: number; | ||
|
||
lessThan(time) { | ||
if (this.greaterThanTime > time) { | ||
throw new Error('Cannot set lessThan less than greaterThan'); | ||
} | ||
|
||
this.lessThanTime = time; | ||
return this; | ||
} | ||
|
||
greaterThan(time) { | ||
if (this.lessThanTime < time) { | ||
throw new Error('Cannot set greaterThan greater than lessThan'); | ||
} | ||
|
||
this.greaterThanTime = time; | ||
return this; | ||
} | ||
} |
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,66 @@ | ||
import assert = require('power-assert'); | ||
|
||
import {Criteria} from '../Criteria'; | ||
import {SummaryResults} from '../../Results/SummaryResults'; | ||
import {HttpRequestRecord} from '../../Steps/Http/HttpRequestRecord'; | ||
import {HttpGetStep} from '../../Steps/Http/HttpGetStep'; | ||
|
||
describe('Criteria', () => { | ||
function getResultsWithAverageResponseTimeOf(averageResponseTime) { | ||
let summaryResults = new SummaryResults(null); | ||
let httpRequestRecord = new HttpRequestRecord(new HttpGetStep(null, null, null, null), { | ||
body: null, | ||
rawBody: null, | ||
statusCode: 200 | ||
}, averageResponseTime, Date.now()); | ||
summaryResults.requests.push(httpRequestRecord); | ||
return summaryResults; | ||
} | ||
|
||
describe('Average Response time', () => { | ||
describe('greaterThan', () => { | ||
it('should allow a greaterThan to be specified', () => { | ||
let criteria = new Criteria(); | ||
criteria.averageResponseTime() | ||
.greaterThan(50); | ||
|
||
let summaryResults = getResultsWithAverageResponseTimeOf(75); | ||
|
||
criteria.validate(summaryResults); | ||
}); | ||
|
||
it('should fail if the average response time is less than the greaterThan', () => { | ||
let criteria = new Criteria(); | ||
criteria.averageResponseTime() | ||
.greaterThan(50); | ||
|
||
let summaryResults = getResultsWithAverageResponseTimeOf(25); | ||
|
||
try { | ||
criteria.validate(summaryResults); | ||
assert.ok(false); | ||
} catch (e) { | ||
assert.ok('Average response time was less tahn 50 ms, failing the build', e.message); | ||
} | ||
}); | ||
|
||
it('should immediately error if a lessThan is set lower than the greaterThan', () => { | ||
try { | ||
new Criteria().averageResponseTime().greaterThan(100).lessThan(50); | ||
assert.ok(false); | ||
} catch (e) { | ||
assert.equal('Cannot set lessThan less than greaterThan', e.message); | ||
} | ||
}); | ||
|
||
it('should immediately error if a greaterThan is set greater than the lessThan', () => { | ||
try { | ||
new Criteria().averageResponseTime().lessThan(150).greaterThan(200); | ||
assert.ok(false); | ||
} catch (e) { | ||
assert.equal('Cannot set greaterThan greater than lessThan', e.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