This repository was archived by the owner on Dec 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 161
feat: Deploy pre-existing package with -p
CLI option
#205
Merged
Merged
Changes from all commits
Commits
Show all changes
2 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
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
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import axios from "axios"; | ||
import MockAdapter from "axios-mock-adapter"; | ||
import mockFs from "mock-fs"; | ||
import path from "path"; | ||
import Serverless from "serverless"; | ||
import { MockFactory } from "../test/mockFactory"; | ||
import { FunctionAppService } from "./functionAppService"; | ||
|
@@ -55,6 +56,9 @@ describe("Function App Service", () => { | |
|
||
mockFs({ | ||
"app.zip": "contents", | ||
".serverless": { | ||
"serviceName.zip": "contents", | ||
} | ||
}, { createCwd: true, createTmp: true }); | ||
}); | ||
|
||
|
@@ -222,6 +226,37 @@ describe("Function App Service", () => { | |
expect(uploadCall[2]).toMatch(/.*-t([0-9]+)/) | ||
}); | ||
|
||
it("uploads functions to function app and blob storage with default naming convention", async () => { | ||
const scmDomain = app.enabledHostNames.find((hostname) => hostname.endsWith("scm.azurewebsites.net")); | ||
const expectedUploadUrl = `https://${scmDomain}/api/zipdeploy/`; | ||
|
||
const sls = MockFactory.createTestServerless(); | ||
delete sls.service["artifact"] | ||
const service = createService(sls); | ||
await service.uploadFunctions(app); | ||
|
||
const defaultArtifact = path.join(".serverless", `${sls.service.getServiceName()}.zip`); | ||
|
||
expect((FunctionAppService.prototype as any).sendFile).toBeCalledWith({ | ||
method: "POST", | ||
uri: expectedUploadUrl, | ||
json: true, | ||
headers: { | ||
Authorization: `Bearer ${variables["azureCredentials"].tokenCache._entries[0].accessToken}`, | ||
Accept: "*/*", | ||
ContentType: "application/octet-stream", | ||
} | ||
}, defaultArtifact); | ||
const expectedArtifactName = service.getDeploymentName().replace("rg-deployment", "artifact"); | ||
expect((AzureBlobStorageService.prototype as any).uploadFile).toBeCalledWith( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: extract |
||
defaultArtifact, | ||
configConstants.deploymentConfig.container, | ||
`${expectedArtifactName}.zip`, | ||
) | ||
const uploadCall = ((AzureBlobStorageService.prototype as any).uploadFile).mock.calls[0]; | ||
expect(uploadCall[2]).toMatch(/.*-t([0-9]+)/) | ||
}); | ||
|
||
it("uploads functions with custom SCM domain (aka App service environments)", async () => { | ||
const customApp = { | ||
...MockFactory.createTestSite("CustomAppWithinASE"), | ||
|
@@ -248,10 +283,19 @@ describe("Function App Service", () => { | |
}, slsService["artifact"]) | ||
}); | ||
|
||
it("throws an error with no zip file", async () => { | ||
it("uses default name when no artifact provided", async () => { | ||
tbarlow12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const sls = MockFactory.createTestServerless(); | ||
delete sls.service["artifact"]; | ||
const service = createService(sls); | ||
await expect(service.uploadFunctions(app)).rejects.not.toBeNull() | ||
expect(service.getFunctionZipFile()).toEqual(path.join(".serverless", `${sls.service.getServiceName()}.zip`)) | ||
}); | ||
|
||
it("uses package param from options if provided", async () => { | ||
const sls = MockFactory.createTestServerless(); | ||
const options = MockFactory.createTestServerlessOptions({ | ||
package: "fake.zip", | ||
}); | ||
const service = createService(sls, options); | ||
expect(service.getFunctionZipFile()).toEqual("fake.zip") | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -92,4 +92,4 @@ export class PackageService { | |
|
||
return Promise.resolve(); | ||
} | ||
} | ||
} |
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.
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.
nit: I would extract the
toBeCalledWith
arguments out just so it's easier to read