Skip to content

Commit

Permalink
feat!: first happy code
Browse files Browse the repository at this point in the history
  • Loading branch information
yicr committed Oct 31, 2024
1 parent 57b59d7 commit ded4db1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
25 changes: 21 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
export class Hello {
public sayHello() {
return 'hello, world!';
import * as crypto from 'crypto';

// Default
// None (stack auto generate)
// string

// export interface Xxx {
// readonly naming: Naming | {functionName: string, roleName: string};
// }

export namespace ResourceNaming {
export enum NamingType {
DEFAULT,
NONE,
}
}

export function createRandomString(value: crypto.BinaryLike, length: number = 8) {
return crypto.createHash('shake256', { outputLength: (length / 2) })
.update(value)
.digest('hex');
}
}
5 changes: 0 additions & 5 deletions test/hello.test.ts

This file was deleted.

22 changes: 22 additions & 0 deletions test/naming.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ResourceNaming } from '../src';

describe('ResouceNaming Testing', () => {

const naming = ((namingType: ResourceNaming.NamingType): string | undefined => {
switch (namingType) {
case ResourceNaming.NamingType.DEFAULT:
const random = ResourceNaming.createRandomString('ResourceName');
return `resource-name-${random}`;
case ResourceNaming.NamingType.NONE:
return undefined;
}
});

it('Is Naming Randmon String', () => {
expect(typeof naming(ResourceNaming.NamingType.DEFAULT)).toBe('string');
});

it('Is Naming undefined', () => {
expect(naming(ResourceNaming.NamingType.NONE)).toBeUndefined();
});
});

0 comments on commit ded4db1

Please sign in to comment.