Skip to content

Commit 6598ab8

Browse files
jeisson-clickupgithub-actions
andauthored
feat(shard): adding capability to add a shard identifier [CU-8x8uvt7f5] (#24)
* feat(shard): adding capability to add a shard indentifier [CU-8x8uvt7f5] * chore: self mutation Signed-off-by: github-actions <github-actions@github.com> --------- Signed-off-by: github-actions <github-actions@github.com> Co-authored-by: github-actions <github-actions@github.com>
1 parent 1c21989 commit 6598ab8

File tree

3 files changed

+95
-20
lines changed

3 files changed

+95
-20
lines changed

API.md

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

src/Shard.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ export interface IShardProps {
1111
* The shard-number within the region.
1212
*/
1313
readonly number: number;
14+
/**
15+
* The shard-identifier.
16+
*/
17+
readonly identifier?: string;
1418
}
1519

1620
export interface IShard extends IShardProps {
@@ -24,11 +28,13 @@ export abstract class Shard implements IShard {
2428
readonly cidr: string;
2529
readonly region: string;
2630
readonly number: number;
31+
readonly identifier: string | undefined;
2732

2833
constructor(props: IShardProps) {
2934
this.cidr = props.cidr;
3035
this.region = props.region;
3136
this.number = props.number;
37+
this.identifier = props.identifier;
3238
}
3339

3440
/**

test/Shard.test.ts

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,58 @@ import { IShard, Shard, IShardProps } from '../src';
33
const env = 'QA';
44
class TestShardImpl extends Shard {
55
get name(): string {
6-
return `${env}_${this.region}_${this.number}`;
6+
const suffix = this.identifier ?? this.number;
7+
return `${env}_${this.region}_${suffix}`;
78
}
89
}
910

10-
const testShardProps: IShardProps = { cidr: 'fakeCidr', region: 'us-west-2', number: 1 };
11+
interface TestCase {
12+
shardsProps: IShardProps;
13+
expectedShardName: string;
14+
isShardIdentifierUndefined?: boolean;
15+
}
16+
const testCases: TestCase[] = [
17+
{
18+
shardsProps: { cidr: 'fakeCidr', region: 'us-west-2', number: 1 },
19+
expectedShardName: 'QA_us-west-2_1',
20+
isShardIdentifierUndefined: true,
21+
},
22+
{
23+
shardsProps: { cidr: 'fakeCidr', region: 'us-east-2', number: 1, identifier: 'global' },
24+
expectedShardName: 'QA_us-east-2_global',
25+
isShardIdentifierUndefined: false,
26+
},
27+
];
28+
29+
describe.each<TestCase>(testCases)(
30+
'Shard implementation: $expectedShardName',
31+
({ shardsProps, expectedShardName, isShardIdentifierUndefined }) => {
32+
let shard: IShard;
1133

12-
let shard: IShard;
13-
describe('Shard', () => {
14-
beforeEach(() => {
15-
shard = new TestShardImpl(testShardProps);
16-
});
34+
beforeEach(() => {
35+
shard = new TestShardImpl(shardsProps);
36+
});
1737

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-
});
38+
it('sets cidr correctly', () => {
39+
expect(shard.cidr).toEqual(shardsProps.cidr);
40+
});
41+
it('sets region correctly', () => {
42+
expect(shard.region).toEqual(shardsProps.region);
43+
});
44+
it('sets number correctly', () => {
45+
expect(shard.number).toEqual(shardsProps.number);
46+
});
47+
it('sets name correctly', () => {
48+
expect(shard.name).toEqual(expectedShardName);
49+
});
50+
if (isShardIdentifierUndefined) {
51+
it('identifier is undefined', () => {
52+
expect(shard.identifier).toBeUndefined();
53+
});
54+
} else {
55+
it('sets identifier correctly', () => {
56+
expect(shard.identifier).toEqual(shardsProps.identifier);
57+
});
58+
}
59+
},
60+
);

0 commit comments

Comments
 (0)