-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate reasonability of
startupGracePeriod
(#827)
* Add validations for the reasonability of startupGracePeriod * Add special handler for default * Fix some schema tests * Refactor assertions
- Loading branch information
Showing
6 changed files
with
163 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { strictEqual, deepStrictEqual } from 'node:assert'; | ||
import { Temporal } from 'temporal-polyfill'; | ||
import { Options } from './schema.ts'; | ||
|
||
export function jsonEqual(actual: unknown, expected: unknown) { | ||
deepStrictEqual(JSON.parse(JSON.stringify(actual)), expected); | ||
} | ||
|
||
export function durationEqual(a: Temporal.Duration, b: Temporal.Duration) { | ||
strictEqual( | ||
Temporal.Duration.compare(a, b), | ||
0, | ||
); | ||
} | ||
|
||
function makeComparableOptions(options: Options): Options { | ||
return { | ||
...options, | ||
waitList: options.waitList.map((w) => ({ | ||
...w, | ||
// Do not use .toJSON(), it does not normalize `seconds: 102` to `PT1M42S`, returns `PT102S` | ||
startupGracePeriodNano: w.startupGracePeriod.total('nanoseconds'), | ||
})), | ||
}; | ||
} | ||
|
||
// Providing to get better result and diff in cases which have Temporal.Duration | ||
// - Object.is() returns `false` even for same total, because they are not idencial | ||
// - deepStrictEqual returns `true` even for different total because of no properties :< | ||
export function optionsEqual(actual: Options, expected: Options) { | ||
deepStrictEqual(makeComparableOptions(actual), makeComparableOptions(expected)); | ||
} |
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