Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 148 additions & 12 deletions API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 24 additions & 5 deletions src/Shard.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface IShard {
export interface IShardProps {
/**
* The cidr for a shard's vpc.
* Regions typically receive a 10.?.0.0/12 address space,
Expand All @@ -10,13 +10,32 @@ export interface IShard {
*/
readonly region: string;
/**
* The proper name for a shard (without numeric suffix).
* The shard-number within the region.
*/
readonly name: string;
readonly number: number;
}

export interface IShard extends IShardProps {
/**
* The shard-number within the region.
* The proper name for a shard (without numeric suffix).
*/
readonly name: string;
}

export abstract class Shard implements IShard {
readonly cidr: string;
readonly region: string;
readonly number: number;

toString(): string;
constructor(props: IShardProps) {
this.cidr = props.cidr;
this.region = props.region;
this.number = props.number;
}

/**
* There are numerous different ways to name a shard. Pick one and stick with
* it.
*/
abstract get name(): string;
}
30 changes: 30 additions & 0 deletions test/Shard.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { IShard, Shard, IShardProps } from '../src';

const env = 'QA';
class TestShardImpl extends Shard {
get name(): string {
return `${env}_${this.region}_${this.number}`;
}
}

const testShardProps: IShardProps = { cidr: '10.0.0.0/0', region: 'us-west-2', number: 1 };

let shard: IShard;
describe('Shard', () => {
beforeEach(() => {
shard = new TestShardImpl(testShardProps);
});

it('sets CIDR correctly', () => {
expect(shard.cidr).toEqual(testShardProps.cidr);
});
it('sets region correctly', () => {
expect(shard.region).toEqual(testShardProps.region);
});
it('sets number correctly', () => {
expect(shard.number).toEqual(testShardProps.number);
});
it('sets name correctly', () => {
expect(shard.name).toEqual('QA_us-west-2_1');
});
});