This repository was archived by the owner on Apr 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Adding spk service get-display-name command #518
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
b4a5c8f
bedrock.yaml refactor & service create spec update
evanlouie 919f23a
bedrock.yaml refactor & service create spec update
evanlouie 8a0bcf6
First pass to get display name for service from bedrock.yaml
samiyaakhtar 9f9a26f
Adding basic unit tests
samiyaakhtar ab72e09
Merge branch 'master' into 1117-bedrock-svc-refactor
samiyaakhtar f32f58c
Fixing generated yaml file
samiyaakhtar a39d0ca
Merge branch '1117-bedrock-svc-refactor' of https://github.com/Cataly…
samiyaakhtar 1376a50
Merge branch '1117-bedrock-svc-refactor' into 1173
samiyaakhtar 7238fb8
Removing the changes that will come after spk release is ready
samiyaakhtar 2db61ce
Updating files
samiyaakhtar cc66c52
Mering from master
samiyaakhtar 7b8346c
Command should be run from bedrock/yaml directory and move under
samiyaakhtar 2a65a57
Minor changes
samiyaakhtar 64e4bcc
Use error chain
samiyaakhtar 0a95bff
Merge branch 'master' into 1173_1
samiyaakhtar c319ce7
More feedback
samiyaakhtar 94c1430
Merge branch 'master' into 1173_1
samiyaakhtar 5792cd3
Improve doc
samiyaakhtar 1295d4b
Merge branch 'master' into 1173_1
samiyaakhtar 2b6eb45
Improve unit test
samiyaakhtar 9f0caf0
Merge branch 'master' into 1173_1
samiyaakhtar 4881044
Merge branch 'master' into 1173_1
samiyaakhtar 253ae29
Separated out negative tests
samiyaakhtar 445024e
Merge branch 'master' into 1173_1
samiyaakhtar 5c3d1de
Merge branch 'master' into 1173_1
yradsmikham 919e59d
Merge branch 'master' into 1173_1
samiyaakhtar b780411
Merge branch 'master' into 1173_1
samiyaakhtar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "command": "get-display-name", | ||
| "alias": "gdn", | ||
| "description": "Gets display name for a service", | ||
| "options": [ | ||
| { | ||
| "arg": "-p, --path <path>", | ||
| "description": "Path to the service folder for which display name is to be extracted", | ||
| "required": true | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| ## Description | ||
|
|
||
| Gets display name of a service based on the provided path by extracting this | ||
| information from bedrock.yaml. This command tries to locate bedrock.yaml in the | ||
| current directory. | ||
|
|
||
| If bedrock.yaml is not found in current directory, the command will fail to | ||
| extract display name. | ||
|
|
||
| If the specified path is not found in any services listed in bedrock.yaml, the | ||
| display name will not be extracted. Make sure that specified path matches the | ||
| path in bedrock.yaml exactly. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { disableVerboseLogging, enableVerboseLogging } from "../../logger"; | ||
| import { execute } from "./get-display-name"; | ||
| import * as fs from "fs"; | ||
| import { createTestBedrockYaml } from "../../test/mockFactory"; | ||
| import { BedrockFile } from "../../types"; | ||
| import * as bedrockYaml from "../../lib/bedrockYaml"; | ||
|
|
||
| beforeAll(() => { | ||
| enableVerboseLogging(); | ||
| }); | ||
|
|
||
| afterAll(() => { | ||
| disableVerboseLogging(); | ||
| }); | ||
|
|
||
| describe("get display name", () => { | ||
| it("positive test", async () => { | ||
| const exitFn = jest.fn(); | ||
| const defaultBedrockFileObject = createTestBedrockYaml( | ||
| false | ||
| ) as BedrockFile; | ||
| jest.spyOn(fs, "existsSync").mockReturnValue(true); | ||
| jest.spyOn(bedrockYaml, "read").mockReturnValue(defaultBedrockFileObject); | ||
| jest.spyOn(process, "cwd").mockReturnValue("bedrock.yaml/"); | ||
| const consoleSpy = jest.spyOn(console, "log"); | ||
| execute({ path: "./packages/service1" }, exitFn); | ||
| expect(consoleSpy).toHaveBeenCalledWith("service1"); | ||
| expect(exitFn).toBeCalledTimes(1); | ||
| expect(exitFn).toBeCalledWith(0); | ||
| }); | ||
| it("negative test", async () => { | ||
| const exitFn = jest.fn(); | ||
| execute({ path: "" }, exitFn); | ||
| expect(exitFn).toBeCalledTimes(1); | ||
| execute({ path: undefined }, exitFn); | ||
| expect(exitFn).toBeCalledWith(1); | ||
| const defaultBedrockFileObject = createTestBedrockYaml( | ||
| false | ||
| ) as BedrockFile; | ||
| jest.spyOn(fs, "existsSync").mockReturnValue(true); | ||
| jest.spyOn(bedrockYaml, "read").mockReturnValue(defaultBedrockFileObject); | ||
| jest.spyOn(process, "cwd").mockReturnValue("bedrock.yaml/"); | ||
| execute({ path: "./packages/service" }, exitFn); // should not exist | ||
| expect(exitFn).toBeCalledTimes(3); | ||
| expect(exitFn).toBeCalledWith(1); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import commander from "commander"; | ||
| import { read as readBedrockYaml } from "../../lib/bedrockYaml"; | ||
| import { build as buildCmd, exit as exitCmd } from "../../lib/commandBuilder"; | ||
| import { logger } from "../../logger"; | ||
| import decorator from "./get-display-name.decorator.json"; | ||
| import { build as buildError, log as logError } from "../../lib/errorBuilder"; | ||
| import { errorStatusCode } from "../../lib/errorStatusCode"; | ||
|
|
||
| export interface CommandOptions { | ||
| path: string | undefined; | ||
| } | ||
|
|
||
| /** | ||
| * Executes the command, can all exit function with 0 or 1 | ||
| * when command completed successfully or failed respectively. | ||
| * | ||
| * @param opts validated option values | ||
| * @param exitFn exit function | ||
| */ | ||
| export const execute = async ( | ||
| opts: CommandOptions, | ||
| exitFn: (status: number) => Promise<void> | ||
| ): Promise<void> => { | ||
| // The assumption is that this command should be ran from the directory where bedrock.yaml exists | ||
| try { | ||
| if (!opts.path) { | ||
| throw buildError( | ||
| errorStatusCode.VALIDATION_ERR, | ||
| "service-get-display-name-path-missing-param-err" | ||
| ); | ||
| } | ||
| const bedrockFile = readBedrockYaml(process.cwd()); | ||
|
samiyaakhtar marked this conversation as resolved.
|
||
| if (!bedrockFile) { | ||
| throw buildError( | ||
| errorStatusCode.FILE_IO_ERR, | ||
| "service-get-display-name-bedrock-yaml-missing-err" | ||
| ); | ||
| } | ||
|
|
||
| const serviceIndex = Object.keys(bedrockFile.services).find( | ||
| (index) => opts.path === bedrockFile.services[+index].path | ||
| ); | ||
|
|
||
| if (serviceIndex) { | ||
| console.log(bedrockFile.services[+serviceIndex].displayName); | ||
|
mtarng marked this conversation as resolved.
|
||
| await exitFn(0); | ||
| } | ||
|
|
||
| throw buildError(errorStatusCode.ENV_SETTING_ERR, { | ||
| errorKey: "service-get-display-name-err", | ||
| values: [opts.path], | ||
| }); | ||
| } catch (err) { | ||
| logError( | ||
| buildError( | ||
| errorStatusCode.VALIDATION_ERR, | ||
| "service-get-display-name-generic-err", | ||
| err | ||
| ) | ||
| ); | ||
| await exitFn(1); | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * Adds the get-display-name command to the commander command object | ||
| * @param command Commander command object to decorate | ||
| */ | ||
| export const commandDecorator = (command: commander.Command): void => { | ||
| buildCmd(command, decorator).action(async (opts: CommandOptions) => { | ||
| await execute(opts, async (status: number) => { | ||
| await exitCmd(logger, process.exit, status); | ||
| }); | ||
| }); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.