-
Notifications
You must be signed in to change notification settings - Fork 4
Support snapshot reference #232
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
Show all changes
6 commits
Select commit
Hold shift + click to select a range
de7781a
wip
zhiyuanliang-ms d8dee3b
support snapshot reference
zhiyuanliang-ms c896e1a
add test
zhiyuanliang-ms 90d0727
update lint rule
zhiyuanliang-ms a2d2782
update
zhiyuanliang-ms a4c0230
Merge branch 'main' into zhiyuanliang/snapshot-reference
zhiyuanliang-ms 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| /* eslint-disable @typescript-eslint/no-unused-expressions */ | ||
| import * as chai from "chai"; | ||
| import chaiAsPromised from "chai-as-promised"; | ||
| chai.use(chaiAsPromised); | ||
| const expect = chai.expect; | ||
| import { load } from "../src/index.js"; | ||
| import { | ||
| mockAppConfigurationClientListConfigurationSettings, | ||
| mockAppConfigurationClientGetSnapshot, | ||
| mockAppConfigurationClientListConfigurationSettingsForSnapshot, | ||
| restoreMocks, | ||
| createMockedConnectionString, | ||
| createMockedKeyValue, | ||
| createMockedSnapshotReference, | ||
| createMockedFeatureFlag, | ||
| sleepInMs | ||
| } from "./utils/testHelper.js"; | ||
| import * as uuid from "uuid"; | ||
|
|
||
| const mockedKVs = [{ | ||
| key: "TestKey1", | ||
| value: "Value1", | ||
| }, { | ||
| key: "TestKey2", | ||
| value: "Value2", | ||
| } | ||
| ].map(createMockedKeyValue); | ||
|
|
||
| mockedKVs.push(createMockedSnapshotReference("TestSnapshotRef", "TestSnapshot1")); | ||
|
|
||
| // TestSnapshot1 | ||
| const snapshot1 = [{ | ||
| key: "TestKey1", | ||
| value: "Value1 in snapshot1", | ||
| } | ||
| ].map(createMockedKeyValue); | ||
| const testFeatureFlag = createMockedFeatureFlag("TestFeatureFlag"); | ||
| snapshot1.push(testFeatureFlag); | ||
|
|
||
| // TestSnapshot2 | ||
| const snapshot2 = [{ | ||
| key: "TestKey1", | ||
| value: "Value1 in snapshot2", | ||
| } | ||
| ].map(createMockedKeyValue); | ||
|
|
||
| describe("snapshot reference", function () { | ||
|
|
||
| beforeEach(() => { | ||
| const snapshotResponses = new Map([ | ||
| ["TestSnapshot1", { compositionType: "key" }], | ||
| ["TestSnapshot2", { compositionType: "key" }]] | ||
| ); | ||
| const snapshotKVs = new Map([ | ||
| ["TestSnapshot1", [snapshot1]], | ||
| ["TestSnapshot2", [snapshot2]]] | ||
| ); | ||
| mockAppConfigurationClientGetSnapshot(snapshotResponses); | ||
| mockAppConfigurationClientListConfigurationSettingsForSnapshot(snapshotKVs); | ||
| mockAppConfigurationClientListConfigurationSettings([mockedKVs]); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| restoreMocks(); | ||
| }); | ||
|
|
||
| it("should resolve snapshot reference", async () => { | ||
| const connectionString = createMockedConnectionString(); | ||
| const settings = await load(connectionString); | ||
| expect(settings.get("TestKey1")).eq("Value1 in snapshot1"); | ||
|
|
||
| // it should ignore feature flags in snapshot | ||
| expect(settings.get(testFeatureFlag.key)).to.be.undefined; | ||
| expect(settings.get("feature_management")).to.be.undefined; | ||
|
|
||
| // it should not load the snapshot reference key | ||
| expect(settings.get("TestSnapshotRef")).to.be.undefined; | ||
| }); | ||
|
|
||
| it("should refresh when snapshot reference changes", async () => { | ||
| const connectionString = createMockedConnectionString(); | ||
| const settings = await load(connectionString, { | ||
| refreshOptions: { | ||
| enabled: true, | ||
| refreshIntervalInMs: 2000 | ||
| } | ||
| }); | ||
| expect(settings.get("TestKey1")).eq("Value1 in snapshot1"); | ||
|
|
||
| const setting = mockedKVs.find(kv => kv.key === "TestSnapshotRef"); | ||
| setting!.value = "{\"snapshot_name\":\"TestSnapshot2\"}"; | ||
| setting!.etag = uuid.v4(); | ||
|
|
||
| await sleepInMs(2 * 1000 + 1); | ||
|
|
||
| await settings.refresh(); | ||
|
|
||
| expect(settings.get("TestKey1")).eq("Value1 in snapshot2"); | ||
| }); | ||
|
|
||
| }); |
Oops, something went wrong.
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.