-
Notifications
You must be signed in to change notification settings - Fork 385
Expand file tree
/
Copy pathPublishToSymbolServerTest.cs
More file actions
299 lines (264 loc) · 13.8 KB
/
PublishToSymbolServerTest.cs
File metadata and controls
299 lines (264 loc) · 13.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Arcade.Test.Common;
using Microsoft.DotNet.Build.Manifest.Tests;
using Microsoft.DotNet.Build.Tasks.Feed.Model;
using Microsoft.DotNet.ProductConstructionService.Client.Models;
using Xunit;
using static Microsoft.DotNet.Internal.SymbolHelper.SymbolPromotionHelper;
namespace Microsoft.DotNet.Build.Tasks.Feed.Tests
{
public class PublishToSymbolServerTest
{
private const string TargetUrl = "TargetUrl";
[Fact]
public void TemporarySymbolsDirectoryTest()
{
var buildEngine = new MockBuildEngine();
var publishTask = new PublishArtifactsInManifestV3()
{
BuildEngine = buildEngine,
};
var path = TestInputs.GetFullPath("Test");
publishTask.EnsureTemporaryDirectoryExists(path);
Assert.True(Directory.Exists(path));
publishTask.DeleteTemporaryDirectory(path);
Assert.False(Directory.Exists(path));
}
[Theory]
[InlineData(SymbolPublishVisibility.Public)]
[InlineData(SymbolPublishVisibility.Internal)]
public void PublishToSymbolServersTest(SymbolPublishVisibility symbolTargetVisibility)
{
var publishTask = new PublishArtifactsInManifestV3();
var feedConfigsForSymbols = new HashSet<TargetFeedConfig>
{
new TargetFeedConfig(
TargetFeedContentType.Symbols,
"TargetUrl",
FeedType.AzDoNugetFeed,
default,
default,
default,
default,
AssetSelection.All,
isolated: true,
@internal: false,
allowOverwrite: true,
symbolTargetVisibility)
};
SymbolPublishVisibility visibility = publishTask.GetSymbolPublishingVisibility(feedConfigsForSymbols);
Assert.Equal(symbolTargetVisibility, visibility);
}
[Fact]
public void EnsureOrderingOfVisibility()
{
Assert.True(SymbolPublishVisibility.Public > SymbolPublishVisibility.Internal);
Assert.True(SymbolPublishVisibility.Internal > SymbolPublishVisibility.None);
Assert.True(Visibility.Public > Visibility.Internal);
}
[Theory]
[InlineData(SymbolPublishVisibility.None)]
[InlineData(SymbolPublishVisibility.Internal)]
[InlineData(SymbolPublishVisibility.Public)]
public void PublishToMultipleServersVisibilityTest(SymbolPublishVisibility maxVisibility)
{
PublishArtifactsInManifestV3 publishTask = new();
HashSet<TargetFeedConfig> feedConfigsForSymbols = [];
IEnumerable<SymbolPublishVisibility> visibilities = Enum.GetValues<SymbolPublishVisibility>().Where(x => x <= maxVisibility);
foreach (SymbolPublishVisibility v in visibilities)
{
feedConfigsForSymbols.Add(
new TargetFeedConfig(
TargetFeedContentType.Symbols,
"testUrl" + v,
FeedType.AzDoNugetFeed,
default,
[],
[],
[],
AssetSelection.All,
isolated: true,
@internal: false,
allowOverwrite: true,
v));
}
SymbolPublishVisibility visibility = publishTask.GetSymbolPublishingVisibility(feedConfigsForSymbols);
Assert.Equal(maxVisibility, visibility);
}
[Fact]
public async Task NoAssetsToPublishFound()
{
(var buildEngine, var task, _, _, _, var buildInfo) = GetCanonicalSymbolTestAssets();
var path = TestInputs.GetFullPath("Symbol");
var buildAsset = ReadOnlyDictionary<string, Asset>.Empty;
// Clear the symbol packages added by the s
task.BlobsByCategory.Clear();
await task.HandleSymbolPublishingAsync(
buildInfo: buildInfo,
assetNameToBARAssetMapping: buildAsset,
pdbArtifactsBasePath: path,
symbolPublishingExclusionsFile: "",
publishSpecialClrFiles: false,
clientThrottle: null);
// TODO: Should this be a warning at least? it used to be an error but it doesn't make as much sense.
// This isn't the best type of test as it tests specifics and not behavior, but the task doesn't
// have interesting observable state.
Assert.Contains(buildEngine.BuildMessageEvents, x => x.Message.StartsWith("No assets to publish"));
}
[Fact]
public async Task NoServersToPublishFound()
{
(var buildEngine, var task, var symbolPackages, _, _, var buildInfo) = GetCanonicalSymbolTestAssets(SymbolPublishVisibility.None);
await task.HandleSymbolPublishingAsync(
buildInfo: buildInfo,
symbolPackages,
pdbArtifactsBasePath: null,
symbolPublishingExclusionsFile: "",
publishSpecialClrFiles: false,
clientThrottle: null);
// This isn't the best type of test as it tests implementation specifics and not behavior, but the task doesn't
// have interesting observable state. It's also a big perf hit to try to not go down this path. As a design decision,
// if symbl type is none we don't even publish to the home/temp tenant.
Assert.Contains(buildEngine.BuildMessageEvents, x => x.Message.StartsWith("No target symbol servers"));
}
[WindowsOnlyFact]
public async Task PublishSymbolsBasicScenarioTest()
{
(var buildEngine, var task, var symbolPackages, var symbolFilesDir, var exclusionFile, var buildInfo) = GetCanonicalSymbolTestAssets(SymbolPublishVisibility.Public);
await task.HandleSymbolPublishingAsync(
buildInfo: buildInfo,
symbolPackages,
pdbArtifactsBasePath: symbolFilesDir,
symbolPublishingExclusionsFile: exclusionFile,
publishSpecialClrFiles: false,
clientThrottle: null,
dryRun: true,
Internal.SymbolHelper.SymbolPromotionHelper.Environment.PPE);
Assert.Empty(buildEngine.BuildErrorEvents);
Assert.Empty(buildEngine.BuildWarningEvents);
// This isn't the best type of test as it tests implementation specifics and not behavior, but the task doesn't
// have interesting observable state.
Assert.Contains(buildEngine.BuildMessageEvents, x => x.Message.StartsWith("Publishing Symbols to Symbol server"));
var message = buildEngine.BuildMessageEvents.Single(x => x.Message.StartsWith("Publishing Symbols to Symbol server"));
Assert.Contains("Symbol packages (1):", message.Message);
Assert.Contains("Loose symbol files (1)", message.Message);
Assert.Contains(buildEngine.BuildMessageEvents, x => x.Message.Contains("Creating symbol request"));
Assert.Equal(2, buildEngine.BuildMessageEvents.Where(x => x.Message.Contains("Adding directory")).Count());
// Message per package per server
Assert.Equal(symbolPackages.Keys.Count, buildEngine.BuildMessageEvents.Where(x => x.Message.Contains($"Extracting symbol package")).Count());
Assert.Equal(symbolPackages.Keys.Count, buildEngine.BuildMessageEvents.Where(x => x.Message.Contains($"Adding package")).Count());
// Make sure exclusions are tracked this should change in conjunction with the exclusion file in the symbols test directory.
Assert.Contains(buildEngine.BuildMessageEvents , x => x.Message.Contains("Skipping lib/net8.0/aztoken.dll"));
Assert.Contains(buildEngine.BuildMessageEvents, x => x.Message.StartsWith("Finished publishing symbols to temporary azdo org"));
Assert.Single(buildEngine.BuildMessageEvents, x => x.Message.StartsWith("Would register request"));
Microsoft.Build.Framework.BuildMessageEventArgs registerLog = buildEngine.BuildMessageEvents.Where(x => x.Message.StartsWith("Would register request")).Single();
Assert.Contains("project dotnettest", registerLog.Message);
Assert.Contains("environment PPE", registerLog.Message);
Assert.Contains("visibility Public", registerLog.Message);
Assert.Contains("to last 3650 days", registerLog.Message);
}
[Fact]
public async Task PublishSymbolsWithPatDoesNotLogDefaultIdentityFallback()
{
(var buildEngine, var task, var symbolPackages, var symbolFilesDir, var exclusionFile, var buildInfo) =
GetCanonicalSymbolTestAssets();
try
{
await task.HandleSymbolPublishingAsync(
buildInfo: buildInfo,
symbolPackages,
pdbArtifactsBasePath: symbolFilesDir,
symbolPublishingExclusionsFile: exclusionFile,
publishSpecialClrFiles: false,
clientThrottle: null,
dryRun: true,
Internal.SymbolHelper.SymbolPromotionHelper.Environment.PPE);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("Windows x64 hosting"))
{
}
Assert.DoesNotContain(buildEngine.BuildMessageEvents, x => x.Message.Contains("Using DefaultIdentityTokenCredential for temporary symbol publishing"));
}
[Fact]
public async Task PublishSymbolsWithoutPatLogsDefaultIdentityFallback()
{
(var buildEngine, var task, var symbolPackages, var symbolFilesDir, var exclusionFile, var buildInfo) =
GetCanonicalSymbolTestAssets(
SymbolPublishVisibility.Public,
tempSymbolsAzureDevOpsOrgToken: null,
managedIdentityClientId: "11111111-1111-1111-1111-111111111111");
try
{
await task.HandleSymbolPublishingAsync(
buildInfo: buildInfo,
symbolPackages,
pdbArtifactsBasePath: symbolFilesDir,
symbolPublishingExclusionsFile: exclusionFile,
publishSpecialClrFiles: false,
clientThrottle: null,
dryRun: true,
Internal.SymbolHelper.SymbolPromotionHelper.Environment.PPE);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("Windows x64 hosting"))
{
}
Assert.Contains(buildEngine.BuildMessageEvents, x => x.Message.Contains("Using DefaultIdentityTokenCredential for temporary symbol publishing"));
}
private static (MockBuildEngine, PublishArtifactsInManifestV3, ReadOnlyDictionary<string, Asset>, string, string, ProductConstructionService.Client.Models.Build) GetCanonicalSymbolTestAssets(
SymbolPublishVisibility targetServer = SymbolPublishVisibility.Public,
string tempSymbolsAzureDevOpsOrgToken = "token",
string managedIdentityClientId = null)
{
const string symbolPackageName= "test-package-a.1.0.0.symbols.nupkg";
var symbolPackages = new Dictionary<string, Asset>()
{
{ symbolPackageName, new(id: 0, buildId: 0, nonShipping: true, name: symbolPackageName, version: "1.0.0", locations: [])}
}.AsReadOnly();
var exclusionFile = TestInputs.GetFullPath("Symbols/SymbolPublishingExclusionsFile.txt");
var symbolFilesDir = TestInputs.GetFullPath("Symbols");
var buildEngine = new MockBuildEngine();
HashSet<TargetFeedConfig> feedConfigsForSymbols = [
new TargetFeedConfig(
TargetFeedContentType.Symbols,
TargetUrl,
FeedType.AzDoNugetFeed,
default,
latestLinkShortUrlPrefixes: [],
akaMSCreateLinkPatterns: [],
akaMSDoNotCreateLinkPatterns: [],
AssetSelection.All,
isolated: true,
@internal: false,
allowOverwrite: true,
targetServer)
];
var task = new PublishArtifactsInManifestV3()
{
BuildEngine = buildEngine,
ArtifactsBasePath = "testPath",
BlobAssetsBasePath = symbolFilesDir,
ManagedIdentityClientId = managedIdentityClientId,
TempSymbolsAzureDevOpsOrg = "dncengtest",
TempSymbolsAzureDevOpsOrgToken = tempSymbolsAzureDevOpsOrgToken,
SymbolRequestProject = "dotnettest"
};
task.FeedConfigs.Add(TargetFeedContentType.Symbols, feedConfigsForSymbols);
task.BlobsByCategory.Add(TargetFeedContentType.Symbols, new HashSet<Manifest.BlobArtifactModel>()
{
new Manifest.BlobArtifactModel()
{
Id = symbolPackageName,
}
});
ProductConstructionService.Client.Models.Build buildInfo = new(id: 4242, DateTimeOffset.Now, staleness: 0, released: false, stable: true, commit: "abcd", [], [], [], []);
return (buildEngine, task, symbolPackages, symbolFilesDir, exclusionFile, buildInfo);
}
}
}