Skip to content

Commit 8096859

Browse files
committed
Add {LogDir} and {TempDir} to set of well-know parameters.
1 parent 26d2f7c commit 8096859

6 files changed

Lines changed: 281 additions & 59 deletions

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.1.37
1+
2.1.38

src/VirtualClient/VirtualClient.Core.UnitTests/ProfileExpressionEvaluatorTests.cs

Lines changed: 158 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,149 @@ internal class ProfileExpressionEvaluatorTests
2323

2424
public void SetupDefaults(PlatformID platform, Architecture architecture = Architecture.X64)
2525
{
26+
// We use 'Unix-style' paths only to avoid issues caused merely by the difference
27+
// between forward-slashes vs. back-slashes. ALL slashes are made forward-slashes to
28+
// simplify the challenge.
2629
this.mockFixture = new MockFixture();
27-
this.mockFixture.Setup(platform, architecture);
30+
this.mockFixture.Setup(platform, architecture, useUnixStylePathsOnly: true);
31+
}
32+
33+
[Test]
34+
public async Task ProfileExpressionEvaluatorSupportsWellKnownExpressionLogPathReferencesOnUnixSystems()
35+
{
36+
this.SetupDefaults(PlatformID.Unix);
37+
string logDirectory = this.mockFixture.GetLogsPath();
38+
string logFilePath = this.mockFixture.GetLogsPath("anylogs", "file1.log");
39+
40+
Dictionary<string, string> expressions = new Dictionary<string, string>
41+
{
42+
{ "{LogPath}", logDirectory },
43+
{ "{LogDir}", logDirectory },
44+
{ "--any-path={LogPath}/anylogs/file1.log", $"--any-path={logFilePath}" },
45+
{ "--any-path={LogDir}/anylogs/file1.log", $"--any-path={logFilePath}" }
46+
};
47+
48+
foreach (var entry in expressions)
49+
{
50+
string expectedExpression = entry.Value;
51+
string actualExpression = await ProfileExpressionEvaluator.Instance.EvaluateAsync(this.mockFixture.Dependencies, entry.Key);
52+
Assert.AreEqual(expectedExpression, actualExpression);
53+
}
54+
}
55+
56+
[Test]
57+
public async Task ProfileExpressionEvaluatorSupportsWellKnownExpressionLogPathReferencesOnWindowsSystems()
58+
{
59+
this.SetupDefaults(PlatformID.Win32NT);
60+
string logDirectory = this.mockFixture.GetLogsPath();
61+
string logFilePath = this.mockFixture.GetLogsPath("anylogs", "file1.log");
62+
63+
Dictionary<string, string> expressions = new Dictionary<string, string>
64+
{
65+
{ "{LogPath}", logDirectory },
66+
{ "{LogDir}", logDirectory },
67+
{ "--any-path={LogPath}/anylogs/file1.log", $"--any-path={logFilePath}" },
68+
{ "--any-path={LogDir}/anylogs/file1.log", $"--any-path={logFilePath}" }
69+
};
70+
71+
foreach (var entry in expressions)
72+
{
73+
string expectedExpression = entry.Value;
74+
string actualExpression = await ProfileExpressionEvaluator.Instance.EvaluateAsync(this.mockFixture.Dependencies, entry.Key);
75+
Assert.AreEqual(expectedExpression, actualExpression);
76+
}
77+
}
78+
79+
[Test]
80+
public async Task ProfileExpressionEvaluatorLogPathLocationReferenceExpressionsAreNotCaseSensitive()
81+
{
82+
this.SetupDefaults(PlatformID.Unix);
83+
string logDirectory = this.mockFixture.GetLogsPath();
84+
85+
Dictionary<string, string> expressions = new Dictionary<string, string>
86+
{
87+
{ "{LogPath}", logDirectory },
88+
{ "{logpath}", logDirectory },
89+
{ "{logdir}", logDirectory },
90+
{ "{LOGPATH}", logDirectory },
91+
{ "{LOGDIR}", logDirectory }
92+
};
93+
94+
foreach (var entry in expressions)
95+
{
96+
string expectedExpression = entry.Value;
97+
string actualExpression = await ProfileExpressionEvaluator.Instance.EvaluateAsync(this.mockFixture.Dependencies, entry.Key);
98+
Assert.AreEqual(expectedExpression, actualExpression);
99+
}
100+
}
101+
102+
[Test]
103+
public async Task ProfileExpressionEvaluatorSupportsWellKnownExpressionTempPathReferencesOnUnixSystems()
104+
{
105+
this.SetupDefaults(PlatformID.Unix);
106+
string tempDirectory = this.mockFixture.GetTempPath();
107+
string tempFilePath = this.mockFixture.GetTempPath("anydir", "temp_file.log");
108+
109+
Dictionary<string, string> expressions = new Dictionary<string, string>
110+
{
111+
{ "{TempPath}", tempDirectory },
112+
{ "{TempDir}", tempDirectory },
113+
{ "--any-path={TempPath}/anydir/temp_file.log", $"--any-path={tempFilePath}" },
114+
{ "--any-path={TempDir}/anydir/temp_file.log", $"--any-path={tempFilePath}" }
115+
};
116+
117+
foreach (var entry in expressions)
118+
{
119+
string expectedExpression = entry.Value;
120+
string actualExpression = await ProfileExpressionEvaluator.Instance.EvaluateAsync(this.mockFixture.Dependencies, entry.Key);
121+
Assert.AreEqual(expectedExpression, actualExpression);
122+
}
123+
}
124+
125+
[Test]
126+
public async Task ProfileExpressionEvaluatorSupportsWellKnownExpressionTempPathReferencesOnWindowsSystems()
127+
{
128+
this.SetupDefaults(PlatformID.Win32NT);
129+
string tempDirectory = this.mockFixture.GetTempPath();
130+
string tempFilePath = this.mockFixture.GetTempPath("anydir", "temp_file.log");
131+
132+
Dictionary<string, string> expressions = new Dictionary<string, string>
133+
{
134+
{ "{TempPath}", tempDirectory },
135+
{ "{TempDir}", tempDirectory },
136+
{ "--any-path={TempPath}/anydir/temp_file.log", $"--any-path={tempFilePath}" },
137+
{ "--any-path={TempDir}/anydir/temp_file.log", $"--any-path={tempFilePath}" }
138+
};
139+
140+
foreach (var entry in expressions)
141+
{
142+
string expectedExpression = entry.Value;
143+
string actualExpression = await ProfileExpressionEvaluator.Instance.EvaluateAsync(this.mockFixture.Dependencies, entry.Key);
144+
Assert.AreEqual(expectedExpression, actualExpression);
145+
}
146+
}
147+
148+
[Test]
149+
public async Task ProfileExpressionEvaluatorTempPathLocationReferenceExpressionsAreNotCaseSensitive()
150+
{
151+
this.SetupDefaults(PlatformID.Unix);
152+
string tempDirectory = this.mockFixture.GetTempPath();
153+
154+
Dictionary<string, string> expressions = new Dictionary<string, string>
155+
{
156+
{ "{TempPath}", tempDirectory },
157+
{ "{temppath}", tempDirectory },
158+
{ "{tempdir}", tempDirectory },
159+
{ "{TEMPPATH}", tempDirectory },
160+
{ "{TEMPDIR}", tempDirectory }
161+
};
162+
163+
foreach (var entry in expressions)
164+
{
165+
string expectedExpression = entry.Value;
166+
string actualExpression = await ProfileExpressionEvaluator.Instance.EvaluateAsync(this.mockFixture.Dependencies, entry.Key);
167+
Assert.AreEqual(expectedExpression, actualExpression);
168+
}
28169
}
29170

30171
[Test]
@@ -39,6 +180,7 @@ public async Task ProfileExpressionEvaluatorSupportsPackagePathLocationReference
39180
Dictionary<string, string> expressions = new Dictionary<string, string>
40181
{
41182
{ "{PackagePath:anyPackage}", packagePath },
183+
{ "{PackageDir:anyPackage}", packagePath },
42184
{ "--any-path={PackagePath:anyPackage}", $"--any-path={packagePath}" }
43185
};
44186

@@ -95,6 +237,7 @@ public async Task ProfileExpressionEvaluatorSupportsPackagePathLocationReference
95237
Dictionary<string, string> expressions = new Dictionary<string, string>
96238
{
97239
{ $"{{PackagePath:{packageName}}}", packagePath },
240+
{ $"{{PackageDir:{packageName}}}", packagePath },
98241
{ $"--any-path={{PackagePath:{packageName}}}", $"--any-path={packagePath}" }
99242
};
100243

@@ -118,6 +261,7 @@ public async Task ProfileExpressionEvaluatorSupportsPackagePathLocationReference
118261
Dictionary<string, string> expressions = new Dictionary<string, string>
119262
{
120263
{ "{PackagePath:anyPackage}", packagePath },
264+
{ "{PackageDir:anyPackage}", packagePath },
121265
{ "--any-path={PackagePath:anyPackage}", $"--any-path={packagePath}" }
122266
};
123267

@@ -171,7 +315,8 @@ public async Task ProfileExpressionEvaluatorPackagePathLocationReferenceExpressi
171315
{
172316
{ "{PackagePath:anyPackage}", packagePath },
173317
{ "{packagepath:anyPackage}", packagePath },
174-
{ "{PACKAGEPATH:anyPackage}", packagePath }
318+
{ "{PACKAGEPATH:anyPackage}", packagePath },
319+
{ "{PACKAGEDIR:anyPackage}", packagePath }
175320
};
176321

177322
foreach (var entry in expressions)
@@ -543,7 +688,7 @@ public void ProfileExpressionEvaluatorThrowsIfTheReferencedParameterIsNotAValidT
543688
}
544689

545690
[Test]
546-
public async Task ProfileExpressionEvaluatorSupportsLogicalCoreCountReferences()
691+
public async Task ProfileExpressionEvaluatorSupportsLogicalProcessorCountReferences()
547692
{
548693
this.SetupDefaults(PlatformID.Win32NT);
549694

@@ -558,11 +703,15 @@ public async Task ProfileExpressionEvaluatorSupportsLogicalCoreCountReferences()
558703
expectedLogicalCores.ToString()
559704
},
560705
{
561-
"--port=1234 --threads={LogicalCoreCount}",
706+
"{LogicalProcessorCount}",
707+
expectedLogicalCores.ToString()
708+
},
709+
{
710+
"--port=1234 --threads={LogicalProcessorCount}",
562711
$"--port=1234 --threads={expectedLogicalCores}"
563712
},
564713
{
565-
"--port=1234 --threads={LogicalCoreCount} --someFlag --clients={LogicalCoreCount}",
714+
"--port=1234 --threads={LogicalProcessorCount} --someFlag --clients={LogicalProcessorCount}",
566715
$"--port=1234 --threads={expectedLogicalCores} --someFlag --clients={expectedLogicalCores}"
567716
}
568717
};
@@ -576,13 +725,13 @@ public async Task ProfileExpressionEvaluatorSupportsLogicalCoreCountReferences()
576725
}
577726

578727
[Test]
579-
public async Task ProfileExpressionEvaluatorSupportsPhysicalCoreCountReferences()
728+
public async Task ProfileExpressionEvaluatorSupportsPhysicalProcessorCountReferences()
580729
{
581730
this.SetupDefaults(PlatformID.Win32NT);
582731

583732
Dictionary<string, string> expressions = new Dictionary<string, string>
584733
{
585-
{ "{PhysicalCoreCount}", "4" },
734+
{ "{PhysicalProcessorCount}", "4" },
586735
{ "--port=1234 --threads={PhysicalCoreCount}", $"--port=1234 --threads=4" },
587736
{ "--port=1234 --threads={PhysicalCoreCount} --someFlag --clients={PhysicalCoreCount}", $"--port=1234 --threads=4 --someFlag --clients=4" }
588737
};
@@ -1080,8 +1229,8 @@ public async Task ProfileExpressionEvaluatorSupportsWellKnownExpressionPackagePa
10801229
[Test]
10811230
[TestCase(PlatformID.Unix, Architecture.X64, "/linux-x64")]
10821231
[TestCase(PlatformID.Unix, Architecture.Arm64, "/linux-arm64")]
1083-
[TestCase(PlatformID.Win32NT, Architecture.X64, "\\win-x64")]
1084-
[TestCase(PlatformID.Win32NT, Architecture.Arm64, "\\win-arm64")]
1232+
[TestCase(PlatformID.Win32NT, Architecture.X64, "/win-x64")]
1233+
[TestCase(PlatformID.Win32NT, Architecture.Arm64, "/win-arm64")]
10851234
public async Task ProfileExpressionEvaluatorSupportsWellKnownExpressionPackagePathPlatform(PlatformID platformID, Architecture architecture, string platform)
10861235
{
10871236
this.SetupDefaults(platformID, architecture);

0 commit comments

Comments
 (0)