Skip to content

Commit a420190

Browse files
nicholibgrainger
authored andcommitted
Remove AppConfig.GetCodeRootPath.
Get this necessary data from config file (like everything else). Always move config.json to output dir. Update the example config.json to show that the CertPath and/or TestDataPath must be specified as so.
1 parent 2a73bcc commit a420190

11 files changed

+44
-30
lines changed

.ci/config/config.buffer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"PasswordlessUser": "no_password",
55
"SecondaryDatabase": "testdb2",
66
"SupportedFeatures": "Json,StoredProcedures,Sha256Password,LargePackets",
7+
8+
"TestData": "../../../../TestData",
79
"MySqlBulkLoaderLocalCsvFile": "%TESTDATA%/LoadData_UTF8_BOM_Unix.CSV",
810
"MySqlBulkLoaderLocalTsvFile": "%TESTDATA%/LoadData_UTF8_BOM_Unix.TSV"
911
}

.ci/config/config.compression+ssl.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
"PasswordlessUser": "no_password",
55
"SecondaryDatabase": "testdb2",
66
"SupportedFeatures": "Json,StoredProcedures,Sha256Password,LargePackets",
7+
8+
"TestData": "../../../../TestData",
79
"MySqlBulkLoaderLocalCsvFile": "%TESTDATA%/LoadData_UTF8_BOM_Unix.CSV",
8-
"MySqlBulkLoaderLocalTsvFile": "%TESTDATA%/LoadData_UTF8_BOM_Unix.TSV"
10+
"MySqlBulkLoaderLocalTsvFile": "%TESTDATA%/LoadData_UTF8_BOM_Unix.TSV",
11+
12+
"CertificatesPath": "../../../../../.ci/server/certs"
913
}
1014
}

.ci/config/config.compression.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"PasswordlessUser": "no_password",
55
"SecondaryDatabase": "testdb2",
66
"SupportedFeatures": "Json,StoredProcedures,Sha256Password,LargePackets",
7+
8+
"TestData": "../../../../TestData",
79
"MySqlBulkLoaderLocalCsvFile": "%TESTDATA%/LoadData_UTF8_BOM_Unix.CSV",
810
"MySqlBulkLoaderLocalTsvFile": "%TESTDATA%/LoadData_UTF8_BOM_Unix.TSV"
911
}

.ci/config/config.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"PasswordlessUser": "no_password",
55
"SecondaryDatabase": "testdb2",
66
"SupportedFeatures": "Json,StoredProcedures,Sha256Password,LargePackets",
7+
8+
"TestData": "../../../../TestData",
79
"MySqlBulkLoaderLocalCsvFile": "%TESTDATA%/LoadData_UTF8_BOM_Unix.CSV",
810
"MySqlBulkLoaderLocalTsvFile": "%TESTDATA%/LoadData_UTF8_BOM_Unix.TSV"
911
}

.ci/config/config.ssl.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
"PasswordlessUser": "no_password",
55
"SecondaryDatabase": "testdb2",
66
"SupportedFeatures": "Json,StoredProcedures,Sha256Password,LargePackets",
7+
8+
"TestData": "../../../../TestData",
79
"MySqlBulkLoaderLocalCsvFile": "%TESTDATA%/LoadData_UTF8_BOM_Unix.CSV",
8-
"MySqlBulkLoaderLocalTsvFile": "%TESTDATA%/LoadData_UTF8_BOM_Unix.TSV"
10+
"MySqlBulkLoaderLocalTsvFile": "%TESTDATA%/LoadData_UTF8_BOM_Unix.TSV",
11+
12+
"CertificatesPath": "../../../../../.ci/server/certs"
913
}
1014
}

.ci/config/config.uds+ssl.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
"PasswordlessUser": "no_password",
55
"SecondaryDatabase": "testdb2",
66
"SupportedFeatures": "Json,StoredProcedures,Sha256Password,LargePackets",
7+
8+
"TestData": "../../../../TestData",
79
"MySqlBulkLoaderLocalCsvFile": "%TESTDATA%/LoadData_UTF8_BOM_Unix.CSV",
8-
"MySqlBulkLoaderLocalTsvFile": "%TESTDATA%/LoadData_UTF8_BOM_Unix.TSV"
10+
"MySqlBulkLoaderLocalTsvFile": "%TESTDATA%/LoadData_UTF8_BOM_Unix.TSV",
11+
12+
"CertificatesPath": "../../../../../.ci/server/certs"
913
}
1014
}

.ci/config/config.uds.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"PasswordlessUser": "no_password",
55
"SecondaryDatabase": "testdb2",
66
"SupportedFeatures": "Json,StoredProcedures,Sha256Password,LargePackets",
7+
8+
"TestData": "../../../../TestData",
79
"MySqlBulkLoaderLocalCsvFile": "%TESTDATA%/LoadData_UTF8_BOM_Unix.CSV",
810
"MySqlBulkLoaderLocalTsvFile": "%TESTDATA%/LoadData_UTF8_BOM_Unix.TSV"
911
}

.ci/run-tests.bat

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@echo off
2-
echo Executing tests with No Compression, No SSL && copy /y tests\SideBySide\config.json.example tests\SideBySide\config.json && dotnet test tests/SideBySide --configuration Release
3-
echo Executing tests with Compression, No SSL && copy /y .ci\config\config.compression.json tests\SideBySide\config.json && dotnet test tests/SideBySide --configuration Release
4-
echo Executing tests with No Compression, SSL && copy /y .ci\config\config.ssl.json tests\SideBySide\config.json && dotnet test tests/SideBySide --configuration Release
5-
echo Executing tests with Compression, SSL && copy /y ".ci\config\config.compression+ssl.json" tests\SideBySide\config.json && dotnet test tests/SideBySide --configuration Release
2+
echo Executing tests with No Compression, No SSL && copy /y .ci\config\config.json tests\SideBySide\config.json && dotnet test tests/SideBySide/SideBySide.csproj --configuration Release
3+
echo Executing tests with Compression, No SSL && copy /y .ci\config\config.compression.json tests\SideBySide\config.json && dotnet test tests/SideBySide/SideBySide.csproj --configuration Release
4+
echo Executing tests with No Compression, SSL && copy /y .ci\config\config.ssl.json tests\SideBySide\config.json && dotnet test tests/SideBySide/SideBySide.csproj --configuration Release
5+
echo Executing tests with Compression, SSL && copy /y ".ci\config\config.compression+ssl.json" tests\SideBySide\config.json && dotnet test tests/SideBySide/SideBySide.csproj --configuration Release

tests/SideBySide/AppConfig.cs

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,14 @@ public static class AppConfig
1919
["Data:SupportsJson"] = "false",
2020
};
2121

22-
private static string CodeRootPath = GetCodeRootPath();
22+
public static string CertsPath => Path.GetFullPath(Config.GetValue<string>("Data:CertificatesPath"));
2323

24-
public static string BasePath = Path.Combine(CodeRootPath, "tests", "SideBySide");
25-
26-
public static string CertsPath = Path.Combine(CodeRootPath, ".ci", "server", "certs");
27-
28-
public static string TestDataPath = Path.Combine(CodeRootPath, "tests", "TestData");
24+
public static string TestDataPath => Path.GetFullPath(Config.GetValue<string>("Data:TestData"));
25+
public static string RemoteTestDataPath => Path.GetFullPath(Config.GetValue<string>("Data:RemoteTestData"));
2926

3027
private static int _configFirst;
3128

3229
private static IConfiguration ConfigBuilder { get; } = new ConfigurationBuilder()
33-
.SetBasePath(BasePath)
3430
.AddInMemoryCollection(DefaultConfig)
3531
.AddJsonFile("config.json")
3632
.Build();
@@ -74,19 +70,6 @@ public static MySqlConnectionStringBuilder CreateSha256ConnectionStringBuilder()
7470
// tests can run much slower in CI environments
7571
public static int TimeoutDelayFactor { get; } = (Environment.GetEnvironmentVariable("APPVEYOR") == "True" || Environment.GetEnvironmentVariable("TRAVIS") == "true") ? 6 : 1;
7672

77-
private static string GetCodeRootPath()
78-
{
79-
#if NET46
80-
var currentAssembly = Assembly.GetExecutingAssembly();
81-
#else
82-
var currentAssembly = typeof(AppConfig).GetTypeInfo().Assembly;
83-
#endif
84-
var directory = new Uri(currentAssembly.CodeBase).LocalPath;
85-
while (!string.Equals(Path.GetFileName(directory), "MySqlConnector", StringComparison.OrdinalIgnoreCase))
86-
directory = Path.GetDirectoryName(directory);
87-
return directory;
88-
}
89-
90-
private static string ExpandVariables(string value) => value?.Replace("%TESTDATA%", TestDataPath);
73+
private static string ExpandVariables(string value) => value?.Replace("%TESTDATA%", TestDataPath).Replace("%REMOTETESTDATA%", RemoteTestDataPath);
9174
}
9275
}

tests/SideBySide/SideBySide.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,10 @@
5151
<Reference Include="Microsoft.CSharp" />
5252
</ItemGroup>
5353

54+
<ItemGroup>
55+
<None Update="config.json">
56+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
57+
</None>
58+
</ItemGroup>
59+
5460
</Project>

0 commit comments

Comments
 (0)