Skip to content

Commit b25df0a

Browse files
Adjust test verification to account for old config stores where 'history' has been cleaned up. (#213)
1 parent 4eb50ed commit b25df0a

1 file changed

Lines changed: 36 additions & 10 deletions

File tree

test/Microsoft.Configuration.ConfigurationBuilders.Test/AzureAppConfigTests.cs

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@ public class AzureAppConfigTests
4545
private readonly string kvUriRegex = "{\"uri\":\".+\"}";
4646

4747

48-
public static bool AppConfigTestsEnabled => false;
48+
// Update this to true to enable AzConfig tests.
49+
public static bool AppConfigTestsEnabled => true;
50+
// Update this to true if the structure of the config store matches what is described below.
51+
// OTOH, if the 'history' of the entries has been lost (cleared after 7 or 30 days depending
52+
// on the subscription plan) then only the most recent values remain and test verification
53+
// will neccessarily be different. Set this to false if 'history' has been cleared away.
54+
public static bool AzConfigHistoryInTact => false;
4955

5056
static AzureAppConfigTests()
5157
{
@@ -368,12 +374,21 @@ private void ValidateExpectedConfig(AzureAppConfigurationBuilder builder, bool o
368374
if (oldTimes)
369375
{
370376
Assert.Equal(untouched ?? "altCaseTestValue", appSettings.Settings["casetestsetting"]?.Value);
371-
Assert.Equal("oldTestValue", appSettings.Settings["testSetting"]?.Value);
377+
if (AzConfigHistoryInTact)
378+
{
379+
Assert.Equal("oldTestValue", appSettings.Settings["testSetting"]?.Value);
380+
Assert.Matches(kvregex ?? kva_value_old, appSettings.Settings["keyVaultSetting"]?.Value);
381+
Assert.Matches(kvregex ?? kvb_value, appSettings.Settings["superKeyVaultSetting"]?.Value);
382+
}
383+
else
384+
{
385+
Assert.Equal(untouched, appSettings.Settings["testSetting"]?.Value);
386+
Assert.Equal(untouched, appSettings.Settings["keyVaultSetting"]?.Value);
387+
Assert.Equal(untouched, appSettings.Settings["superKeyVaultSetting"]?.Value);
388+
}
372389
Assert.Equal(untouched, appSettings.Settings["newTestSetting"]?.Value);
373390
Assert.Equal("oldSuperValue", appSettings.Settings["superTestSetting"]?.Value);
374-
Assert.Matches(kvregex ?? kva_value_old, appSettings.Settings["keyVaultSetting"]?.Value);
375-
Assert.Matches(kvregex ?? kvb_value, appSettings.Settings["superKeyVaultSetting"]?.Value);
376-
Assert.Equal(greedy ? 5 : 6, appSettings.Settings.Count); // "newTestSetting" is staged "in the xml" when not greedy.
391+
Assert.Equal(greedy ? (AzConfigHistoryInTact ? 5 : 2) : 6, appSettings.Settings.Count); // "newTestSetting" is staged "in the xml" when not greedy.
377392
}
378393
else
379394
{
@@ -396,8 +411,11 @@ private void ValidateExpectedConfig(AzureAppConfigurationBuilder builder, bool o
396411
Assert.Equal(untouched, appSettings.Settings["newTestSetting"]?.Value);
397412
Assert.Equal("oldSuperValue", appSettings.Settings["superTestSetting"]?.Value);
398413
Assert.Equal(untouched, appSettings.Settings["keyVaultSetting"]?.Value);
399-
Assert.Matches(kvregex ?? kvb_value, appSettings.Settings["superKeyVaultSetting"]?.Value);
400-
Assert.Equal(greedy ? 3 : 6, appSettings.Settings.Count);
414+
if (AzConfigHistoryInTact)
415+
Assert.Matches(kvregex ?? kvb_value, appSettings.Settings["superKeyVaultSetting"]?.Value);
416+
else
417+
Assert.Equal(untouched, appSettings.Settings["superKeyVaultSetting"]?.Value);
418+
Assert.Equal(greedy ? (AzConfigHistoryInTact ? 3 : 2) : 6, appSettings.Settings.Count);
401419
}
402420
else
403421
{
@@ -416,12 +434,20 @@ private void ValidateExpectedConfig(AzureAppConfigurationBuilder builder, bool o
416434
if (oldTimes)
417435
{
418436
Assert.Equal(untouched ?? "altCaseTestValue", appSettings.Settings["casetestsetting"]?.Value);
419-
Assert.Equal("altTestValue", appSettings.Settings["testSetting"]?.Value);
437+
if (AzConfigHistoryInTact)
438+
{
439+
Assert.Equal("altTestValue", appSettings.Settings["testSetting"]?.Value);
440+
Assert.Matches(kvregex ?? kva_value_new, appSettings.Settings["keyVaultSetting"]?.Value);
441+
}
442+
else
443+
{
444+
Assert.Equal(untouched, appSettings.Settings["testSetting"]?.Value);
445+
Assert.Equal(untouched, appSettings.Settings["keyVaultSetting"]?.Value);
446+
}
420447
Assert.Equal(untouched, appSettings.Settings["newTestSetting"]?.Value);
421448
Assert.Equal(untouched, appSettings.Settings["superTestSetting"]?.Value);
422-
Assert.Matches(kvregex ?? kva_value_new, appSettings.Settings["keyVaultSetting"]?.Value);
423449
Assert.Equal(untouched, appSettings.Settings["superKeyVaultSetting"]?.Value);
424-
Assert.Equal(greedy ? 3 : 6, appSettings.Settings.Count);
450+
Assert.Equal(greedy ? (AzConfigHistoryInTact ? 3 : 1): 6, appSettings.Settings.Count);
425451
}
426452
else
427453
{

0 commit comments

Comments
 (0)