-
Notifications
You must be signed in to change notification settings - Fork 0
Advertise binary diff capability to the server #63
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
Merged
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| import * as assert from "assert"; | ||
| import * as querystring from "querystring"; | ||
|
|
||
| import * as acquisitionSdk from "../acquisition-sdk"; | ||
| import * as mockApi from "./acquisition-rest-mock"; | ||
|
|
||
| const configuration: acquisitionSdk.Configuration = { | ||
| appVersion: "1.5.0", | ||
| clientUniqueId: "My iPhone", | ||
| deploymentKey: mockApi.validDeploymentKey, | ||
| serverUrl: mockApi.serverUrl, | ||
| enableDeltaUpdates: true | ||
| }; | ||
|
|
||
| const deltaUpdatesDisabledConfiguration: acquisitionSdk.Configuration = { ...configuration, enableDeltaUpdates: undefined }; | ||
|
|
||
| const currentPackage: acquisitionSdk.Package = { | ||
| deploymentKey: mockApi.validDeploymentKey, | ||
| description: "Standard description", | ||
| label: "v1", | ||
| appVersion: "1.5.0", | ||
| packageHash: "hash001", | ||
| isMandatory: false, | ||
| packageSize: 100 | ||
| }; | ||
|
|
||
| const okResponse: acquisitionSdk.Http.Response = { | ||
| statusCode: 200, | ||
| body: JSON.stringify({ update_info: { is_available: false } }) | ||
| }; | ||
|
|
||
| // Captures the exact request the SDK sends, instead of simulating a server response - the | ||
| // point of these tests is what goes over the wire, not how the SDK reacts to a reply. | ||
| class CapturingRequester implements acquisitionSdk.Http.Requester { | ||
| public lastUrl: string; | ||
| public lastBody: string; | ||
|
|
||
| public request( | ||
| verb: acquisitionSdk.Http.Verb, | ||
| url: string, | ||
| requestBodyOrCallback: string | acquisitionSdk.Callback<acquisitionSdk.Http.Response>, | ||
| callback?: acquisitionSdk.Callback<acquisitionSdk.Http.Response> | ||
| ): void { | ||
| this.lastUrl = url; | ||
|
|
||
| if (typeof requestBodyOrCallback === "string") { | ||
| this.lastBody = requestBodyOrCallback; | ||
| callback(/*error*/ null, okResponse); | ||
| } else { | ||
| requestBodyOrCallback(/*error*/ null, okResponse); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| describe("Capabilities advertisement", () => { | ||
| it("update_check sends capabilities as a plain repeated query param, not bracketed", (done: Mocha.Done) => { | ||
| var requester = new CapturingRequester(); | ||
| var acquisition = new acquisitionSdk.AcquisitionManager(requester, configuration); | ||
|
|
||
| acquisition.queryUpdateWithCurrentPackage(currentPackage, () => { | ||
| var query = requester.lastUrl.split("?")[1]; | ||
| var params = querystring.parse(query); | ||
|
|
||
| assert.strictEqual(params.capabilities, "binary_diff:bsdiff"); | ||
| assert.strictEqual(query.includes("capabilities%5B%5D"), false, "must not use bracket notation"); | ||
| done(); | ||
| }); | ||
| }); | ||
|
|
||
| it("update_check omits undefined optional fields instead of the literal string \"undefined\"", (done: Mocha.Done) => { | ||
| var requester = new CapturingRequester(); | ||
| var acquisition = new acquisitionSdk.AcquisitionManager(requester, configuration); | ||
| var freshInstallPackage: acquisitionSdk.Package = { ...currentPackage, packageHash: undefined, label: undefined }; | ||
|
|
||
| acquisition.queryUpdateWithCurrentPackage(freshInstallPackage, () => { | ||
| var query = requester.lastUrl.split("?")[1]; | ||
| var params = querystring.parse(query); | ||
|
|
||
| assert.strictEqual(params.package_hash, undefined); | ||
| assert.strictEqual(params.label, undefined); | ||
| assert.strictEqual(query.includes("undefined"), false); | ||
| done(); | ||
| }); | ||
| }); | ||
|
|
||
| it("report_status/deploy sends capabilities as a JSON array", (done: Mocha.Done) => { | ||
| var requester = new CapturingRequester(); | ||
| var acquisition = new acquisitionSdk.AcquisitionManager(requester, configuration); | ||
|
|
||
| acquisition.reportStatusDeploy( | ||
| currentPackage, | ||
| acquisitionSdk.AcquisitionStatus.DeploymentSucceeded, | ||
| /*previousLabelOrAppVersion*/ undefined, | ||
| /*previousDeploymentKey*/ undefined, | ||
| () => { | ||
| var body = JSON.parse(requester.lastBody); | ||
|
|
||
| assert.deepStrictEqual(body.capabilities, ["binary_diff:bsdiff"]); | ||
| done(); | ||
| } | ||
| ); | ||
| }); | ||
|
|
||
| it("update_check sends no capabilities when delta updates are not enabled", (done: Mocha.Done) => { | ||
| var requester = new CapturingRequester(); | ||
| var acquisition = new acquisitionSdk.AcquisitionManager(requester, deltaUpdatesDisabledConfiguration); | ||
|
|
||
| acquisition.queryUpdateWithCurrentPackage(currentPackage, () => { | ||
| var params = querystring.parse(requester.lastUrl.split("?")[1]); | ||
|
|
||
| assert.strictEqual(params.capabilities, undefined); | ||
| done(); | ||
| }); | ||
| }); | ||
|
|
||
| it("report_status/deploy sends an empty capabilities array when delta updates are not enabled", (done: Mocha.Done) => { | ||
| var requester = new CapturingRequester(); | ||
| var acquisition = new acquisitionSdk.AcquisitionManager(requester, deltaUpdatesDisabledConfiguration); | ||
|
|
||
| acquisition.reportStatusDeploy( | ||
| currentPackage, | ||
| acquisitionSdk.AcquisitionStatus.DeploymentSucceeded, | ||
| /*previousLabelOrAppVersion*/ undefined, | ||
| /*previousDeploymentKey*/ undefined, | ||
| () => { | ||
| var body = JSON.parse(requester.lastBody); | ||
|
|
||
| assert.deepStrictEqual(body.capabilities, []); | ||
| done(); | ||
| } | ||
| ); | ||
| }); | ||
| }); |
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 |
|---|---|---|
|
|
@@ -46,6 +46,10 @@ async function setPlistStringValue(plistPath: string, key: string, value: string | |
| await promisify(childProcess.execFile)("plutil", ["-replace", key, "-string", value, plistPath]); | ||
| } | ||
|
|
||
| async function setPlistBoolValue(plistPath: string, key: string, value: boolean): Promise<void> { | ||
| await promisify(childProcess.execFile)("plutil", ["-replace", key, "-bool", String(value), plistPath]); | ||
|
Collaborator
Author
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.
|
||
| } | ||
|
|
||
| /** | ||
| * Returns a " --platform <ios|android>" flag for `expo prebuild` when exactly one platform is | ||
| * under test in this mocha run, so prebuild only regenerates that platform's native project | ||
|
|
@@ -253,6 +257,7 @@ class RNIOS extends Platform.IOS implements RNPlatform { | |
| .then(() => setPlistStringValue(infoPlistPath, "CodePushDeploymentKey", this.getDefaultDeploymentKey())) | ||
| .then(() => setPlistStringValue(infoPlistPath, "CodePushServerURL", this.getServerUrl())) | ||
| .then(() => setPlistStringValue(infoPlistPath, "CodePushPublicKey", codeSigningPublicKey)) | ||
| .then(() => setPlistBoolValue(infoPlistPath, "CodePushEnableDeltaUpdates", true)) | ||
| // Fix the linker flag list in project.pbxproj (pod install adds an extra comma) | ||
| .then(TestUtil.replaceString.bind(undefined, path.join(iOSProject, TestConfig.TestAppName + ".xcodeproj", "project.pbxproj"), | ||
| "\"[$][(]inherited[)]\",\\s*[)];", "\"$(inherited)\"\n\t\t\t\t);")) | ||
|
|
@@ -865,6 +870,8 @@ PluginTestingFramework.initializeTests(new RNProjectManager(), supportedTargetPl | |
| try { | ||
| assert.notStrictEqual(null, request); | ||
| assert.strictEqual(request.query.deployment_key, targetPlatform.getDefaultDeploymentKey()); | ||
| // The test apps enable delta updates, so this checks the flag end to end: native config -> getConfiguration() -> SDK. | ||
| assert.strictEqual(request.query.capabilities, "binary_diff:bsdiff"); | ||
| } catch (e) { | ||
| done(e); | ||
| } | ||
|
|
||
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.
Decided to split the fix into its own PR: #64