Skip to content

Commit

Permalink
test: add generateTerraformResource function
Browse files Browse the repository at this point in the history
  • Loading branch information
giovannibaratta committed Dec 8, 2023
1 parent 61cb602 commit a6ba251
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 0 deletions.
Binary file not shown.
Binary file not shown.
32 changes: 32 additions & 0 deletions core/libs/testing/src/random.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// eslint-disable-next-line node/no-unpublished-import
import {Chance} from "chance"

interface Resource extends ResourceIdentifier {
resourceAddress: string
}

interface ResourceIdentifier {
resourceType: string
resourceName: string
}

const randomGenerator = new Chance()

export function generateTerraformResource(
partial?: Partial<ResourceIdentifier>
): Resource {
const defaultValues: ResourceIdentifier = {
resourceType: randomGenerator.word(),
resourceName: randomGenerator.word()
}

const resourceIdentifier = {
...defaultValues,
...partial
}

return {
...resourceIdentifier,
resourceAddress: `${resourceIdentifier.resourceType}.${resourceIdentifier.resourceName}`
}
}
2 changes: 2 additions & 0 deletions core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@
"@nestjs/cli": "10.2.1",
"@nestjs/schematics": "10.0.3",
"@nestjs/testing": "10.2.8",
"@types/chance": "1.1.6",
"@types/inquirer": "9.0.7",
"@types/jest": "29.5.8",
"@types/node": "18.18.9",
"@typescript-eslint/eslint-plugin": "6.10.0",
"@typescript-eslint/parser": "6.10.0",
"chance": "1.1.11",
"eslint": "8.53.0",
"eslint-config-prettier": "8.10.0",
"eslint-plugin-jest": "27.6.0",
Expand Down
16 changes: 16 additions & 0 deletions core/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,13 @@ __metadata:
languageName: node
linkType: hard

"@types/chance@npm:^1.1.6":
version: 1.1.6
resolution: "@types/chance@npm:1.1.6"
checksum: a1845ff0a70989d581b8f7628aaef1807276c0ae22d0c038013ebcac4f4bd57e6a765319377994cc3cae2122838638fdb2afe5232ee6b987b3f7ea2cddecbead
languageName: node
linkType: hard

"@types/eslint-scope@npm:^3.7.3":
version: 3.7.7
resolution: "@types/eslint-scope@npm:3.7.7"
Expand Down Expand Up @@ -2224,6 +2231,13 @@ __metadata:
languageName: node
linkType: hard

"chance@npm:1.1.11":
version: 1.1.11
resolution: "chance@npm:1.1.11"
checksum: 2e871fcc76584d274f860f0f25380b6ab547caf0d22d8b043a313be73d5c3db38941373241f83aeba049e7511f752f9746dc722a0f2b0182020d493c4e11da84
languageName: node
linkType: hard

"char-regex@npm:^1.0.2":
version: 1.0.2
resolution: "char-regex@npm:1.0.2"
Expand Down Expand Up @@ -6224,12 +6238,14 @@ __metadata:
"@nestjs/core": 10.2.8
"@nestjs/schematics": 10.0.3
"@nestjs/testing": 10.2.8
"@types/chance": ^1.1.6
"@types/inquirer": 9.0.7
"@types/jest": 29.5.8
"@types/node": 18.18.9
"@typescript-eslint/eslint-plugin": 6.10.0
"@typescript-eslint/parser": 6.10.0
ajv: 8.12.0
chance: 1.1.11
eslint: 8.53.0
eslint-config-prettier: 8.10.0
eslint-plugin-jest: 27.6.0
Expand Down

0 comments on commit a6ba251

Please sign in to comment.