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
Add unit test for spk service create-revision command #282
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
64e8560
948: Add unit test for spk service create-revision
edaena ccc770c
Fix lint errors
edaena b6bf5fa
Add function documentation
edaena dd3248d
Updates based on feedback
edaena 69da6eb
Merge master into branch
edaena ffb6035
Add missing test
edaena 8c80fbf
Update test case
edaena 9b78c3e
Merge branch 'master' into revision-test
yradsmikham 58a2149
Fix lint error
edaena 38258f2
Remove unused imports
edaena 75002e3
Add test
edaena 3dac3bb
Merge branch 'master' into revision-test
samiyaakhtar f1581e7
Edit function return value
edaena 21f0464
Merge branch 'master' of github.com:CatalystCode/spk into revision-test
edaena 515e282
Merge branch 'revision-test' of github.com:CatalystCode/spk into revi…
edaena a20f81b
Merge branch 'master' into revision-test
mtarng 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,167 @@ | ||
| import { write } from "../../config"; | ||
| import * as azure from "../../lib/git/azure"; | ||
| import * as gitutils from "../../lib/gitutils"; | ||
| import { createTempDir } from "../../lib/ioUtil"; | ||
| import { IBedrockFile } from "../../types"; | ||
| import { | ||
| getDefaultRings, | ||
| getSourceBranch, | ||
| makePullRequest | ||
| } from "./create-revision"; | ||
|
|
||
| jest | ||
| .spyOn(gitutils, "getCurrentBranch") | ||
| .mockReturnValueOnce(Promise.resolve("prod")) | ||
| .mockReturnValue(Promise.resolve("")); | ||
| const prSpy = jest | ||
| .spyOn(azure, "createPullRequest") | ||
| .mockReturnValue(Promise.resolve("done")); | ||
|
|
||
| describe("Default rings", () => { | ||
| test("Get multiple default rings", () => { | ||
| const randomTmpDir = createTempDir(); | ||
| const validBedrockYaml: IBedrockFile = { | ||
| rings: { | ||
| master: { isDefault: true }, | ||
| prod: { isDefault: false }, | ||
| westus: { isDefault: true } | ||
| }, | ||
| services: { | ||
| "foo/a": { | ||
| helm: { | ||
| chart: { | ||
| chart: "elastic", | ||
| repository: "some-repo" | ||
| } | ||
| }, | ||
| k8sBackend: "backendservice", | ||
| k8sBackendPort: 1337, | ||
| pathPrefix: "servicepath", | ||
| pathPrefixMajorVersion: "v1" | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| write(validBedrockYaml, randomTmpDir); | ||
| const defaultRings = getDefaultRings(undefined, validBedrockYaml); | ||
| expect(defaultRings.length).toBe(2); | ||
| expect(defaultRings[0]).toBe("master"); | ||
| expect(defaultRings[1]).toBe("westus"); | ||
| }); | ||
|
|
||
| test("No default rings", () => { | ||
| const randomTmpDir = createTempDir(); | ||
| const validBedrockYaml: IBedrockFile = { | ||
| rings: { | ||
| master: { isDefault: false }, | ||
| prod: { isDefault: false }, | ||
| westus: { isDefault: false } | ||
| }, | ||
| services: { | ||
| "foo/a": { | ||
| helm: { | ||
| chart: { | ||
| chart: "elastic", | ||
| repository: "some-repo" | ||
| } | ||
| }, | ||
| k8sBackend: "backendservice", | ||
| k8sBackendPort: 1337, | ||
| pathPrefix: "servicepath", | ||
| pathPrefixMajorVersion: "v1" | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| write(validBedrockYaml, randomTmpDir); | ||
| let hasError = false; | ||
|
|
||
| try { | ||
| getDefaultRings(undefined, validBedrockYaml); | ||
| } catch (err) { | ||
| hasError = true; | ||
| } | ||
| expect(hasError).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe("Source branch", () => { | ||
| test("Defined source branch", async () => { | ||
| const branch = "master"; | ||
| const sourceBranch = await getSourceBranch(branch); | ||
| expect(sourceBranch).toBe("master"); | ||
| }); | ||
| test("Defined source branch", async () => { | ||
| const branch = undefined; | ||
| const sourceBranch = await getSourceBranch(branch); | ||
| expect(sourceBranch).toBe("prod"); | ||
| }); | ||
| test("No source branch", async () => { | ||
| const branch = undefined; | ||
| let hasError = false; | ||
| try { | ||
| await getSourceBranch(branch); | ||
| } catch (err) { | ||
| hasError = true; | ||
| } | ||
| expect(hasError).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe("Create pull request", () => { | ||
| test("invalid parameters", async () => { | ||
| for (const i of Array(4).keys()) { | ||
| let hasError = false; | ||
| try { | ||
| await makePullRequest( | ||
| ["master"], | ||
| "testTitle", | ||
| i === 0 ? undefined : "branch", | ||
| "description", | ||
| i === 1 ? undefined : "org", | ||
| i === 2 ? undefined : "url", | ||
| i === 3 ? undefined : "token" | ||
| ); | ||
| } catch (err) { | ||
| hasError = true; | ||
| } | ||
| expect(hasError).toBe(true); | ||
| } | ||
| }); | ||
| test("Valid parameters", async () => { | ||
| await makePullRequest( | ||
| ["master"], | ||
| "testTitle", | ||
| "testBranch", | ||
| "testDescription", | ||
| "testOrg", | ||
| "testUrl", | ||
| "testToken" | ||
| ); | ||
| expect(prSpy).toHaveBeenCalled(); | ||
| }); | ||
| test("Default description", async () => { | ||
| await makePullRequest( | ||
| ["master"], | ||
| "testTitle", | ||
| "testBranch", | ||
| undefined, | ||
| "testOrg", | ||
| "testUrl", | ||
| "testToken" | ||
| ); | ||
| expect(prSpy).toHaveBeenCalled(); | ||
| }); | ||
| test("Default title", async () => { | ||
| await makePullRequest( | ||
| ["master"], | ||
| undefined, | ||
| "testBranch", | ||
| "description", | ||
| "testOrg", | ||
| "testUrl", | ||
| "testToken" | ||
| ); | ||
| expect(prSpy).toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
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.