Move Test Config to Jsonc#4297
Conversation
| public string DNSCachingConnString = null; | ||
| public string DNSCachingServerCR = null; // this is for the control ring | ||
| public string DNSCachingServerTR = null; // this is for the tenant ring | ||
| public bool IsAzureSynapse = false; // True for Azure Data Warehouse/Synapse |
There was a problem hiding this comment.
This was removed as it is not used.
| public string AliasName = null; | ||
|
|
||
| public static Config Load(string configPath = @"config.json") | ||
| public static Config Load(string configPath) |
There was a problem hiding this comment.
This was added as an escape hatch for preserving the behavior of ExtUtilities project. I have plans to remove the ExtUtilities project, so this method will hopefully go away someday.
| "WorkloadIdentityFederationServiceConnectionId": "", | ||
| "KerberosDomainPassword": "", | ||
| "KerberosDomainuser": "", | ||
| "IsManagedInstance": false |
There was a problem hiding this comment.
These fields exist in Config class, but did not in the json file.
| "SupportsIntegratedSecurity": true, | ||
| "LocalDbAppName": "", | ||
| "LocalDbSharedInstanceName": "", | ||
| "SupportsFileStream": false, |
There was a problem hiding this comment.
This field did not exist in the Config class.
| "DNSCachingServerTR": "", | ||
| "IsDNSCachingSupportedCR": false, | ||
| "IsDNSCachingSupportedTR": false, | ||
| "IsAzureSynapse": false, |
There was a problem hiding this comment.
This field existed in the Config class, but was removed since it's unused.
There was a problem hiding this comment.
Pull request overview
This PR updates the test utilities configuration workflow to support JSON-with-comments by moving the default test config to .jsonc, adjusting config-loading precedence, and enabling nullable reference types in the config model.
Changes:
- Renames the default test config to
config.default.jsoncand updates build logic to create/copyconfig.jsonc. - Updates
Config.Loadbehavior to probe config locations in a new order and enables#nullable. - Updates ignore rules to exclude
config.jsoncfrom source control.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Microsoft.Data.SqlClient.TestUtilities.csproj | Copies default config to config.jsonc and sets output-copy metadata. |
| src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/config.default.jsonc | Updates the sample config content and adds/adjusts fields. |
| src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Config.cs | Refactors config load logic, adds jsonc/json probing, and enables nullable annotations. |
| .gitignore | Ignores generated config.jsonc files. |
Comments suppressed due to low confidence (3)
src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Config.cs:96
LoadInternalonly catchesFileNotFoundException. IfTEST_MDS_CONFIG(or another attempted path) points to a non-existent directory,StreamReaderwill throwDirectoryNotFoundExceptionand short-circuit the intended fallback to other locations. Consider treatingDirectoryNotFoundException(and possibly other path-related IO exceptions) the same as file-not-found for the multi-location probe.
try
{
using StreamReader sr = new StreamReader(configPath);
return JsonConvert.DeserializeObject<Config>(sr.ReadToEnd()) ??
throw new InvalidOperationException($"Failed to deserialize config from '{configPath}'");
}
catch (FileNotFoundException)
{
// File did not exist at the path given. We will try a different location.
return null;
}
src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Config.cs:76
UpdateConfigstill defaults to writingconfig.json, butLoad()now prefersconfig.jsoncwhen both exist. This can lead to updating one file while reads continue to use the other. Consider updating the default toconfig.jsonc, or writing to whichever config file was actually loaded/exists to avoid divergence.
public static void UpdateConfig(Config updatedConfig, string configPath = @"config.json")
{
string config = JsonConvert.SerializeObject(updatedConfig);
File.WriteAllText(configPath, config);
src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/config.default.jsonc:40
- Possible typo in the sample config key:
KerberosDomainuserdoesn't match theKerberosDomainUserfield name used in code. Aligning the casing/spelling will make the sample easier to follow (even if deserialization is case-insensitive).
| public static Config Load(string configPath) | ||
| { | ||
| // Allow an override of the config path via an environment variable. | ||
| configPath = Environment.GetEnvironmentVariable("TEST_MDS_CONFIG") ?? configPath; | ||
| Config config = LoadInternal(Environment.GetEnvironmentVariable("TEST_MDS_CONFIG")) ?? | ||
| LoadInternal(configPath) ?? | ||
| throw new FileNotFoundException("Could not find test configuration file."); | ||
|
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 14 changed files in this pull request and generated 4 comments.
Comments suppressed due to low confidence (1)
src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/config.default.jsonc:40
- Property name
KerberosDomainuserhas inconsistent casing vs the code/config consumers (KerberosDomainUser, e.g.,Config.KerberosDomainUserand Kerberos pipeline steps). With System.Text.Json’s default case-sensitive matching this won’t bind as intended. Rename the JSON property toKerberosDomainUser(and keep casing consistent for other acronyms, e.g.,URL).
| { | ||
| if (configPath is null) | ||
| { | ||
| return null; | ||
| } | ||
|
|
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| </None> | ||
| <PackageReference Include="Newtonsoft.Json" /> | ||
| <None Update="config.jsonc" CopyToOutputDirectory="PreserveNewest" /> |
| You can override the config file path with the `MDS_TEST_CONFIG` environment variable: | ||
|
|
||
| ```bash | ||
| MDS_TEST_CONFIG=/path/to/config.json dotnet build -t:TestSqlClientManual -p:TestSet=2 | ||
| MDS_TEST_CONFIG=/path/to/config.jsonc dotnet build -t:TestSqlClientManual -p:TestSet=2 | ||
| ``` |
| Edit the source configuration file at `src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/ | ||
| config.json`. The test utilities project copies that file to the test output directory, where the manual tests load it | ||
| config.jsonc`. The test utilities project copies that file to the test output directory, where the manual tests load it | ||
| by default. |
| You can override the config file path with the `MDS_TEST_CONFIG` environment variable: | ||
|
|
||
| ```bash | ||
| MDS_TEST_CONFIG=/path/to/config.json dotnet build -t:TestSqlClientManual -p:TestSet=2 | ||
| MDS_TEST_CONFIG=/path/to/config.jsonc dotnet build -t:TestSqlClientManual -p:TestSet=2 | ||
| ``` | ||
|
|
||
| On PowerShell: | ||
|
|
||
| ```powershell | ||
| $env:MDS_TEST_CONFIG = "C:\path\to\config.json" | ||
| $env:MDS_TEST_CONFIG = "C:\path\to\config.jsonc" | ||
| dotnet build -t:TestSqlClientManual -p:TestSet=2 |
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| </None> | ||
| <PackageReference Include="Newtonsoft.Json" /> | ||
| <None Update="config.jsonc" CopyToOutputDirectory="PreserveNewest" /> |
| # All properties should be added here, and this template should be used for any manipulation of the config.jsonc file. | ||
| - pwsh: | | ||
| $jdata = Get-Content -Raw "config.default.json" | ConvertFrom-Json | ||
| $jdata = Get-Content -Raw "config.default.jsonc" | ConvertFrom-Json |
| - pwsh: | | ||
| $managedSni = [System.Convert]::ToBoolean($env:MANAGED_SNI) | ||
| $jdata = Get-Content -Raw "config.default.json" | ConvertFrom-Json | ||
| $jdata = Get-Content -Raw "config.default.jsonc" | ConvertFrom-Json | ||
| foreach ($p in $jdata) { | ||
| $p.TCPConnectionString = $env:REMOTE_TCP_CONN_STRING | ||
| $p.NPConnectionString = $env:REMOTE_NP_CONN_STRING | ||
| $p.SupportsIntegratedSecurity = $true | ||
| $p.UseManagedSNIOnWindows = $managedSni | ||
| } | ||
| $jdata | ConvertTo-Json | Set-Content "config.json" | ||
| $jdata | ConvertTo-Json | Set-Content "config.jsonc" |
| <Target Name="CopyConfig" BeforeTargets="Compile"> | ||
| <Copy SourceFiles="config.default.json" DestinationFiles="config.json" Condition="!Exists('config.json')" /> | ||
| <Copy SourceFiles="config.default.jsonc" DestinationFiles="config.jsonc" Condition="!Exists('config.jsonc')" /> | ||
| </Target> | ||
| <ItemGroup> | ||
| <None Update="config.json"> | ||
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| </None> | ||
| <PackageReference Include="Newtonsoft.Json" /> | ||
| <None Update="config.jsonc" CopyToOutputDirectory="PreserveNewest" /> | ||
| </ItemGroup> |
| catch (FileNotFoundException) | ||
| { | ||
| // File did not exist at the path given. We will try a different location. |
| You can override the config file path with the `MDS_TEST_CONFIG` environment variable: | ||
|
|
||
| ```bash | ||
| MDS_TEST_CONFIG=/path/to/config.json dotnet build -t:TestSqlClientManual -p:TestSet=2 | ||
| MDS_TEST_CONFIG=/path/to/config.jsonc dotnet build -t:TestSqlClientManual -p:TestSet=2 | ||
| ``` |
| Edit the source configuration file at `src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/ | ||
| config.json`. The test utilities project copies that file to the test output directory, where the manual tests load it | ||
| config.jsonc`. The test utilities project copies that file to the test output directory, where the manual tests load it | ||
| by default. |
5885bb9 to
57e9b41
Compare
| # All properties should be added here, and this template should be used for any manipulation of the config.jsonc file. | ||
| - pwsh: | | ||
| $jdata = Get-Content -Raw "config.default.json" | ConvertFrom-Json | ||
| $jdata = Get-Content -Raw "config.default.jsonc" | ConvertFrom-Json |
| - pwsh: | | ||
| $managedSni = [System.Convert]::ToBoolean($env:MANAGED_SNI) | ||
| $jdata = Get-Content -Raw "config.default.json" | ConvertFrom-Json | ||
| $jdata = Get-Content -Raw "config.default.jsonc" | ConvertFrom-Json | ||
| foreach ($p in $jdata) { | ||
| $p.TCPConnectionString = $env:REMOTE_TCP_CONN_STRING | ||
| $p.NPConnectionString = $env:REMOTE_NP_CONN_STRING | ||
| $p.SupportsIntegratedSecurity = $true | ||
| $p.UseManagedSNIOnWindows = $managedSni | ||
| } | ||
| $jdata | ConvertTo-Json | Set-Content "config.json" | ||
| $jdata | ConvertTo-Json | Set-Content "config.jsonc" |
| You can override the config file path with the `MDS_TEST_CONFIG` environment variable: | ||
|
|
||
| ```bash | ||
| MDS_TEST_CONFIG=/path/to/config.json dotnet build -t:TestSqlClientManual -p:TestSet=2 | ||
| MDS_TEST_CONFIG=/path/to/config.jsonc dotnet build -t:TestSqlClientManual -p:TestSet=2 | ||
| ``` | ||
|
|
||
| On PowerShell: | ||
|
|
||
| ```powershell | ||
| $env:MDS_TEST_CONFIG = "C:\path\to\config.json" | ||
| $env:MDS_TEST_CONFIG = "C:\path\to\config.jsonc" | ||
| dotnet build -t:TestSqlClientManual -p:TestSet=2 | ||
| ``` |
| catch (FileNotFoundException) | ||
| { | ||
| // File did not exist at the path given. We will try a different location. |
Description
As a byproduct of the PR pipeline, I got annoyed with the red squigglies under the comments in the test config.json file. Technically speaking jsonc files support comments while json does not. So, this small PR does the following:
#nullableIssues
N/A
Testing
Everything builds, but I want to validate with a PR run before taking it out of draft state.