Skip to content

Commit 9794cfc

Browse files
authored
feat(infra): Expose abstract Shard class [CLK-187171] (#3)
1 parent b0c3262 commit 9794cfc

File tree

3 files changed

+202
-17
lines changed

3 files changed

+202
-17
lines changed

API.md

Lines changed: 148 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Shard.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export interface IShard {
1+
export interface IShardProps {
22
/**
33
* The cidr for a shard's vpc.
44
* Regions typically receive a 10.?.0.0/12 address space,
@@ -10,13 +10,32 @@ export interface IShard {
1010
*/
1111
readonly region: string;
1212
/**
13-
* The proper name for a shard (without numeric suffix).
13+
* The shard-number within the region.
1414
*/
15-
readonly name: string;
15+
readonly number: number;
16+
}
17+
18+
export interface IShard extends IShardProps {
1619
/**
17-
* The shard-number within the region.
20+
* The proper name for a shard (without numeric suffix).
1821
*/
22+
readonly name: string;
23+
}
24+
25+
export abstract class Shard implements IShard {
26+
readonly cidr: string;
27+
readonly region: string;
1928
readonly number: number;
2029

21-
toString(): string;
30+
constructor(props: IShardProps) {
31+
this.cidr = props.cidr;
32+
this.region = props.region;
33+
this.number = props.number;
34+
}
35+
36+
/**
37+
* There are numerous different ways to name a shard. Pick one and stick with
38+
* it.
39+
*/
40+
abstract get name(): string;
2241
}

test/Shard.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { IShard, Shard, IShardProps } from '../src';
2+
3+
const env = 'QA';
4+
class TestShardImpl extends Shard {
5+
get name(): string {
6+
return `${env}_${this.region}_${this.number}`;
7+
}
8+
}
9+
10+
const testShardProps: IShardProps = { cidr: '10.0.0.0/0', region: 'us-west-2', number: 1 };
11+
12+
let shard: IShard;
13+
describe('Shard', () => {
14+
beforeEach(() => {
15+
shard = new TestShardImpl(testShardProps);
16+
});
17+
18+
it('sets CIDR correctly', () => {
19+
expect(shard.cidr).toEqual(testShardProps.cidr);
20+
});
21+
it('sets region correctly', () => {
22+
expect(shard.region).toEqual(testShardProps.region);
23+
});
24+
it('sets number correctly', () => {
25+
expect(shard.number).toEqual(testShardProps.number);
26+
});
27+
it('sets name correctly', () => {
28+
expect(shard.name).toEqual('QA_us-west-2_1');
29+
});
30+
});

0 commit comments

Comments
 (0)