-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix(extensions): skip extensions deploy when there is nothing to deploy #10925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
IzaakGough
wants to merge
3
commits into
main
Choose a base branch
from
@invertase/fix-issue-7584
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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,78 @@ | ||
| import { expect } from "chai"; | ||
| import * as sinon from "sinon"; | ||
|
|
||
| import { deploy } from "./deploy"; | ||
| import { Context, Payload } from "./args"; | ||
| import * as cloudbilling from "../../gcp/cloudbilling"; | ||
| import * as provisioningHelper from "../../extensions/provisioningHelper"; | ||
|
|
||
| describe("Extensions deploy", () => { | ||
| let checkBillingEnabledStub: sinon.SinonStub; | ||
| let bulkCheckProductsProvisionedStub: sinon.SinonStub; | ||
|
|
||
| const options: any = { nonInteractive: true, project: "test-project" }; | ||
| const instance = (instanceId: string) => ({ instanceId, params: {}, systemParams: {} }) as any; | ||
|
Check warning on line 14 in src/deploy/extensions/deploy.spec.ts
|
||
|
|
||
| beforeEach(() => { | ||
| checkBillingEnabledStub = sinon.stub(cloudbilling, "checkBillingEnabled").resolves(true); | ||
| bulkCheckProductsProvisionedStub = sinon | ||
| .stub(provisioningHelper, "bulkCheckProductsProvisioned") | ||
| .resolves(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| sinon.restore(); | ||
| }); | ||
|
|
||
| it("should do nothing when there is nothing to deploy", async () => { | ||
| // A functions deploy for a codebase that declares no extensions reaches this | ||
| // stage with an empty payload, and must not require the Cloud Billing API. | ||
| await deploy({} as Context, options, {} as Payload); | ||
|
|
||
| expect(checkBillingEnabledStub.called).to.be.false; | ||
| expect(bulkCheckProductsProvisionedStub.called).to.be.false; | ||
| }); | ||
|
|
||
| it("should do nothing when the payload only has empty instance lists", async () => { | ||
| const payload: Payload = { | ||
| instancesToCreate: [], | ||
| instancesToUpdate: [], | ||
| instancesToConfigure: [], | ||
| instancesToDelete: [], | ||
| }; | ||
|
|
||
| await deploy({} as Context, options, payload); | ||
|
|
||
| expect(checkBillingEnabledStub.called).to.be.false; | ||
| expect(bulkCheckProductsProvisionedStub.called).to.be.false; | ||
| }); | ||
|
|
||
| it("should deploy normally when there is an instance to create", async () => { | ||
| const payload: Payload = { instancesToCreate: [instance("new-instance")] }; | ||
|
|
||
| await deploy({} as Context, options, payload); | ||
|
|
||
| expect(checkBillingEnabledStub.calledWith("test-project")).to.be.true; | ||
| // Asserted so that widening the empty-payload guard above cannot silently turn | ||
| // a real deploy into a no-op. | ||
| expect(bulkCheckProductsProvisionedStub.called).to.be.true; | ||
| }); | ||
|
|
||
| it("should not skip a delete-only deploy", async () => { | ||
| const payload: Payload = { instancesToDelete: [instance("doomed")] }; | ||
|
|
||
| await deploy({} as Context, options, payload); | ||
|
|
||
| expect(checkBillingEnabledStub.called).to.be.true; | ||
| expect(bulkCheckProductsProvisionedStub.called).to.be.true; | ||
| }); | ||
|
|
||
| it("should deploy normally when only configuring an instance", async () => { | ||
| const payload: Payload = { instancesToConfigure: [instance("existing")] }; | ||
|
|
||
| await deploy({} as Context, options, payload); | ||
|
|
||
| expect(checkBillingEnabledStub.called).to.be.true; | ||
| expect(bulkCheckProductsProvisionedStub.called).to.be.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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using
anyas an escape hatch for theoptionsvariable, as it violates the repository style guide (TypeScript section, line 37). Instead, importOptionsfrom../../optionsand cast the mock object asOptions.References
anyorunknownas an escape hatch. Define proper interfaces/types or use type guards. (link)