Skip to content

Commit 0f534f5

Browse files
authored
Refactor and update unit-tests (#418)
* Update unit-tests and dotnet-install scripts
1 parent fc8786b commit 0f534f5

9 files changed

+867
-641
lines changed

.github/workflows/e2e-tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- name: Clear toolcache
2525
shell: pwsh
2626
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
27-
- name: Setup dotnet 2.2.402 and 3.1.404
27+
- name: Setup dotnet 2.2.402, 3.1.404 and 3.0.x
2828
uses: ./
2929
with:
3030
dotnet-version: |

__tests__/__snapshots__/authutil.test.ts.snap

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`authutil tests Existing config not in repo root, sets up a partial NuGet.config user/PAT for GPR 1`] = `
3+
exports[`authutil tests existing config not in repo root, sets up a partial NuGet.config user/PAT for GPR 1`] = `
44
"<?xml version=\\"1.0\\"?>
55
<configuration>
66
<config>
@@ -15,7 +15,7 @@ exports[`authutil tests Existing config not in repo root, sets up a partial NuGe
1515
</configuration>"
1616
`;
1717
18-
exports[`authutil tests Existing config w/ Azure Artifacts source and NuGet.org, sets up a partial NuGet.config user/PAT for GPR 1`] = `
18+
exports[`authutil tests existing config w/ Azure Artifacts source and NuGet.org, sets up a partial NuGet.config user/PAT for GPR 1`] = `
1919
"<?xml version=\\"1.0\\"?>
2020
<configuration>
2121
<config>
@@ -30,7 +30,7 @@ exports[`authutil tests Existing config w/ Azure Artifacts source and NuGet.org,
3030
</configuration>"
3131
`;
3232
33-
exports[`authutil tests Existing config w/ GPR source and NuGet.org, sets up a partial NuGet.config user/PAT for GPR 1`] = `
33+
exports[`authutil tests existing config w/ GPR source and NuGet.org, sets up a partial NuGet.config user/PAT for GPR 1`] = `
3434
"<?xml version=\\"1.0\\"?>
3535
<configuration>
3636
<config>
@@ -45,7 +45,7 @@ exports[`authutil tests Existing config w/ GPR source and NuGet.org, sets up a p
4545
</configuration>"
4646
`;
4747
48-
exports[`authutil tests Existing config w/ no GPR sources, sets up a full NuGet.config with URL and user/PAT for GPR 1`] = `
48+
exports[`authutil tests existing config w/ no GPR sources, sets up a full NuGet.config with URL and user/PAT for GPR 1`] = `
4949
"<?xml version=\\"1.0\\"?>
5050
<configuration>
5151
<config>
@@ -63,7 +63,7 @@ exports[`authutil tests Existing config w/ no GPR sources, sets up a full NuGet.
6363
</configuration>"
6464
`;
6565
66-
exports[`authutil tests Existing config w/ no sources, sets up a full NuGet.config with URL and user/PAT for GPR 1`] = `
66+
exports[`authutil tests existing config w/ no sources, sets up a full NuGet.config with URL and user/PAT for GPR 1`] = `
6767
"<?xml version=\\"1.0\\"?>
6868
<configuration>
6969
<config>
@@ -81,7 +81,7 @@ exports[`authutil tests Existing config w/ no sources, sets up a full NuGet.conf
8181
</configuration>"
8282
`;
8383
84-
exports[`authutil tests Existing config w/ only Azure Artifacts source, sets up a partial NuGet.config user/PAT for GPR 1`] = `
84+
exports[`authutil tests existing config w/ only Azure Artifacts source, sets up a partial NuGet.config user/PAT for GPR 1`] = `
8585
"<?xml version=\\"1.0\\"?>
8686
<configuration>
8787
<config>
@@ -96,7 +96,7 @@ exports[`authutil tests Existing config w/ only Azure Artifacts source, sets up
9696
</configuration>"
9797
`;
9898
99-
exports[`authutil tests Existing config w/ only GPR source, sets up a partial NuGet.config user/PAT for GPR 1`] = `
99+
exports[`authutil tests existing config w/ only GPR source, sets up a partial NuGet.config user/PAT for GPR 1`] = `
100100
"<?xml version=\\"1.0\\"?>
101101
<configuration>
102102
<config>
@@ -111,7 +111,7 @@ exports[`authutil tests Existing config w/ only GPR source, sets up a partial Nu
111111
</configuration>"
112112
`;
113113
114-
exports[`authutil tests Existing config w/ two GPR sources, sets up a partial NuGet.config user/PAT for GPR 1`] = `
114+
exports[`authutil tests existing config w/ two GPR sources, sets up a partial NuGet.config user/PAT for GPR 1`] = `
115115
"<?xml version=\\"1.0\\"?>
116116
<configuration>
117117
<config>
@@ -130,7 +130,7 @@ exports[`authutil tests Existing config w/ two GPR sources, sets up a partial Nu
130130
</configuration>"
131131
`;
132132
133-
exports[`authutil tests No existing config, sets up a full NuGet.config with URL and other owner/PAT for GPR 1`] = `
133+
exports[`authutil tests no existing config, sets up a full NuGet.config with URL and other owner/PAT for GPR 1`] = `
134134
"<?xml version=\\"1.0\\"?>
135135
<configuration>
136136
<config>
@@ -148,7 +148,7 @@ exports[`authutil tests No existing config, sets up a full NuGet.config with URL
148148
</configuration>"
149149
`;
150150
151-
exports[`authutil tests No existing config, sets up a full NuGet.config with URL and token for other source 1`] = `
151+
exports[`authutil tests no existing config, sets up a full NuGet.config with URL and token for other source 1`] = `
152152
"<?xml version=\\"1.0\\"?>
153153
<configuration>
154154
<config>
@@ -166,7 +166,7 @@ exports[`authutil tests No existing config, sets up a full NuGet.config with URL
166166
</configuration>"
167167
`;
168168
169-
exports[`authutil tests No existing config, sets up a full NuGet.config with URL and user/PAT for GPR 1`] = `
169+
exports[`authutil tests no existing config, sets up a full NuGet.config with URL and user/PAT for GPR 1`] = `
170170
"<?xml version=\\"1.0\\"?>
171171
<configuration>
172172
<config>

__tests__/authutil.test.ts

+28-28
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ describe('authutil tests', () => {
9191
process.env['NUGET_AUTH_TOKEN'] = '';
9292
});
9393

94-
it('No existing config, sets up a full NuGet.config with URL and user/PAT for GPR', async () => {
94+
it('no existing config, sets up a full NuGet.config with URL and user/PAT for GPR', async () => {
9595
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
96-
await auth.configAuthentication(
96+
auth.configAuthentication(
9797
'https://nuget.pkg.github.com/OwnerName/index.json',
9898
'',
9999
fakeSourcesDirForTesting
@@ -104,10 +104,10 @@ describe('authutil tests', () => {
104104
).toMatchSnapshot();
105105
});
106106

107-
it('No existing config, auth token environment variable not provided, throws', async () => {
107+
it('no existing config, auth token environment variable not provided, throws', async () => {
108108
let thrown = false;
109109
try {
110-
await auth.configAuthentication(
110+
auth.configAuthentication(
111111
'https://nuget.pkg.github.com/OwnerName/index.json',
112112
'',
113113
fakeSourcesDirForTesting
@@ -118,10 +118,10 @@ describe('authutil tests', () => {
118118
expect(thrown).toBe(true);
119119
});
120120

121-
it('No existing config, sets up a full NuGet.config with URL and other owner/PAT for GPR', async () => {
121+
it('no existing config, sets up a full NuGet.config with URL and other owner/PAT for GPR', async () => {
122122
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
123123
process.env['INPUT_OWNER'] = 'otherorg';
124-
await auth.configAuthentication(
124+
auth.configAuthentication(
125125
'https://nuget.pkg.github.com/otherorg/index.json',
126126
'',
127127
fakeSourcesDirForTesting
@@ -132,7 +132,7 @@ describe('authutil tests', () => {
132132
).toMatchSnapshot();
133133
});
134134

135-
it('Existing config (invalid), tries to parse an invalid NuGet.config and throws', async () => {
135+
it('existing config (invalid), tries to parse an invalid NuGet.config and throws', async () => {
136136
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
137137
const inputNuGetConfigPath: string = path.join(
138138
fakeSourcesDirForTesting,
@@ -141,7 +141,7 @@ describe('authutil tests', () => {
141141
fs.writeFileSync(inputNuGetConfigPath, invalidNuGetConfig);
142142
let thrown = false;
143143
try {
144-
await auth.configAuthentication(
144+
auth.configAuthentication(
145145
'https://nuget.pkg.github.com/OwnerName/index.json',
146146
'',
147147
fakeSourcesDirForTesting
@@ -152,14 +152,14 @@ describe('authutil tests', () => {
152152
expect(thrown).toBe(true);
153153
});
154154

155-
it('Existing config w/ no sources, sets up a full NuGet.config with URL and user/PAT for GPR', async () => {
155+
it('existing config w/ no sources, sets up a full NuGet.config with URL and user/PAT for GPR', async () => {
156156
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
157157
const inputNuGetConfigPath: string = path.join(
158158
fakeSourcesDirForTesting,
159159
'nuget.config'
160160
);
161161
fs.writeFileSync(inputNuGetConfigPath, emptyNuGetConfig);
162-
await auth.configAuthentication(
162+
auth.configAuthentication(
163163
'https://nuget.pkg.github.com/OwnerName/index.json',
164164
'',
165165
fakeSourcesDirForTesting
@@ -170,14 +170,14 @@ describe('authutil tests', () => {
170170
).toMatchSnapshot();
171171
});
172172

173-
it('Existing config w/ no GPR sources, sets up a full NuGet.config with URL and user/PAT for GPR', async () => {
173+
it('existing config w/ no GPR sources, sets up a full NuGet.config with URL and user/PAT for GPR', async () => {
174174
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
175175
const inputNuGetConfigPath: string = path.join(
176176
fakeSourcesDirForTesting,
177177
'nuget.config'
178178
);
179179
fs.writeFileSync(inputNuGetConfigPath, nugetorgNuGetConfig);
180-
await auth.configAuthentication(
180+
auth.configAuthentication(
181181
'https://nuget.pkg.github.com/OwnerName/index.json',
182182
'',
183183
fakeSourcesDirForTesting
@@ -188,14 +188,14 @@ describe('authutil tests', () => {
188188
).toMatchSnapshot();
189189
});
190190

191-
it('Existing config w/ only GPR source, sets up a partial NuGet.config user/PAT for GPR', async () => {
191+
it('existing config w/ only GPR source, sets up a partial NuGet.config user/PAT for GPR', async () => {
192192
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
193193
const inputNuGetConfigPath: string = path.join(
194194
fakeSourcesDirForTesting,
195195
'nuget.config'
196196
);
197197
fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig);
198-
await auth.configAuthentication(
198+
auth.configAuthentication(
199199
'https://nuget.pkg.github.com/OwnerName/index.json',
200200
'',
201201
fakeSourcesDirForTesting
@@ -206,14 +206,14 @@ describe('authutil tests', () => {
206206
).toMatchSnapshot();
207207
});
208208

209-
it('Existing config w/ GPR source and NuGet.org, sets up a partial NuGet.config user/PAT for GPR', async () => {
209+
it('existing config w/ GPR source and NuGet.org, sets up a partial NuGet.config user/PAT for GPR', async () => {
210210
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
211211
const inputNuGetConfigPath: string = path.join(
212212
fakeSourcesDirForTesting,
213213
'nuget.config'
214214
);
215215
fs.writeFileSync(inputNuGetConfigPath, gprnugetorgNuGetConfig);
216-
await auth.configAuthentication(
216+
auth.configAuthentication(
217217
'https://nuget.pkg.github.com/OwnerName/index.json',
218218
'',
219219
fakeSourcesDirForTesting
@@ -224,14 +224,14 @@ describe('authutil tests', () => {
224224
).toMatchSnapshot();
225225
});
226226

227-
it('Existing config w/ two GPR sources, sets up a partial NuGet.config user/PAT for GPR', async () => {
227+
it('existing config w/ two GPR sources, sets up a partial NuGet.config user/PAT for GPR', async () => {
228228
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
229229
const inputNuGetConfigPath: string = path.join(
230230
fakeSourcesDirForTesting,
231231
'nuget.config'
232232
);
233233
fs.writeFileSync(inputNuGetConfigPath, twogprNuGetConfig);
234-
await auth.configAuthentication(
234+
auth.configAuthentication(
235235
'https://nuget.pkg.github.com',
236236
'',
237237
fakeSourcesDirForTesting
@@ -242,7 +242,7 @@ describe('authutil tests', () => {
242242
).toMatchSnapshot();
243243
});
244244

245-
it('Existing config w/ spaces in key, throws for now', async () => {
245+
it('existing config w/ spaces in key, throws for now', async () => {
246246
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
247247
const inputNuGetConfigPath: string = path.join(
248248
fakeSourcesDirForTesting,
@@ -251,7 +251,7 @@ describe('authutil tests', () => {
251251
fs.writeFileSync(inputNuGetConfigPath, spaceNuGetConfig);
252252
let thrown = false;
253253
try {
254-
await auth.configAuthentication(
254+
auth.configAuthentication(
255255
'https://nuget.pkg.github.com/OwnerName/index.json',
256256
'',
257257
fakeSourcesDirForTesting
@@ -262,7 +262,7 @@ describe('authutil tests', () => {
262262
expect(thrown).toBe(true);
263263
});
264264

265-
it('Existing config not in repo root, sets up a partial NuGet.config user/PAT for GPR', async () => {
265+
it('existing config not in repo root, sets up a partial NuGet.config user/PAT for GPR', async () => {
266266
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
267267
const inputNuGetConfigDirectory: string = path.join(
268268
fakeSourcesDirForTesting,
@@ -274,7 +274,7 @@ describe('authutil tests', () => {
274274
);
275275
fs.mkdirSync(inputNuGetConfigDirectory, {recursive: true});
276276
fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig);
277-
await auth.configAuthentication(
277+
auth.configAuthentication(
278278
'https://nuget.pkg.github.com/OwnerName/index.json',
279279
'subfolder/nuget.config',
280280
fakeSourcesDirForTesting
@@ -285,14 +285,14 @@ describe('authutil tests', () => {
285285
).toMatchSnapshot();
286286
});
287287

288-
it('Existing config w/ only Azure Artifacts source, sets up a partial NuGet.config user/PAT for GPR', async () => {
288+
it('existing config w/ only Azure Artifacts source, sets up a partial NuGet.config user/PAT for GPR', async () => {
289289
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
290290
const inputNuGetConfigPath: string = path.join(
291291
fakeSourcesDirForTesting,
292292
'nuget.config'
293293
);
294294
fs.writeFileSync(inputNuGetConfigPath, azureartifactsNuGetConfig);
295-
await auth.configAuthentication(
295+
auth.configAuthentication(
296296
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
297297
'',
298298
fakeSourcesDirForTesting
@@ -303,14 +303,14 @@ describe('authutil tests', () => {
303303
).toMatchSnapshot();
304304
});
305305

306-
it('Existing config w/ Azure Artifacts source and NuGet.org, sets up a partial NuGet.config user/PAT for GPR', async () => {
306+
it('existing config w/ Azure Artifacts source and NuGet.org, sets up a partial NuGet.config user/PAT for GPR', async () => {
307307
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
308308
const inputNuGetConfigPath: string = path.join(
309309
fakeSourcesDirForTesting,
310310
'nuget.config'
311311
);
312312
fs.writeFileSync(inputNuGetConfigPath, azureartifactsnugetorgNuGetConfig);
313-
await auth.configAuthentication(
313+
auth.configAuthentication(
314314
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
315315
'',
316316
fakeSourcesDirForTesting
@@ -321,9 +321,9 @@ describe('authutil tests', () => {
321321
).toMatchSnapshot();
322322
});
323323

324-
it('No existing config, sets up a full NuGet.config with URL and token for other source', async () => {
324+
it('no existing config, sets up a full NuGet.config with URL and token for other source', async () => {
325325
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
326-
await auth.configAuthentication(
326+
auth.configAuthentication(
327327
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
328328
'',
329329
fakeSourcesDirForTesting

__tests__/csc.test.ts

+33-9
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,45 @@
11
import cscFile from '../.github/csc.json';
22
describe('csc tests', () => {
3-
it('Valid regular expression', async () => {
4-
const regex = cscFile['problemMatcher'][0]['pattern'][0]['regexp'];
3+
test('regular expression in csc.json is valid', async () => {
4+
const regexPattern = cscFile['problemMatcher'][0]['pattern'][0]['regexp'];
5+
const regexResultsMap = cscFile['problemMatcher'][0]['pattern'][0];
56

6-
console.log(regex);
7-
const re = new RegExp(regex);
7+
const regex = new RegExp(regexPattern);
88

9-
// Ideally we would verify that this
109
const stringsToMatch = [
1110
'Program.cs(10,79): error CS1002: ; expected [/Users/zacharyeisinger/Documents/repo/setup-dotnet/__tests__/sample-broken-csproj/sample.csproj]',
1211
"S:\\Msbuild\\src\\Build\\Evaluation\\ExpressionShredder.cs(33,7): error CS1003: Syntax error, ',' expected [S:\\msbuild\\src\\Build\\Microsoft.Build.csproj > Properties:prop]"
1312
];
13+
// Expected results are calculated according to the csc matcher located in csc.json file
14+
const expectedResults = [
15+
{
16+
file: 'Program.cs',
17+
line: '10',
18+
severity: 'error',
19+
code: 'CS1002',
20+
message: '; expected',
21+
fromPath:
22+
'/Users/zacharyeisinger/Documents/repo/setup-dotnet/__tests__/sample-broken-csproj/sample.csproj'
23+
},
24+
{
25+
file: 'S:\\Msbuild\\src\\Build\\Evaluation\\ExpressionShredder.cs',
26+
line: '33',
27+
severity: 'error',
28+
code: 'CS1003',
29+
message: "Syntax error, ',' expected",
30+
fromPath:
31+
'S:\\msbuild\\src\\Build\\Microsoft.Build.csproj > Properties:prop'
32+
}
33+
];
1434

15-
stringsToMatch.forEach(string => {
16-
const matchStr = string.match(re);
17-
console.log(matchStr);
18-
expect(matchStr).toEqual(expect.anything());
35+
stringsToMatch.map((string, index) => {
36+
const matchedResultsArray = string.match(regex);
37+
for (const propName in expectedResults[index]) {
38+
const propertyIndex = regexResultsMap[propName];
39+
const expectedPropValue = expectedResults[index][propName];
40+
const matchedPropValue = matchedResultsArray![propertyIndex];
41+
expect(matchedPropValue).toEqual(expectedPropValue);
42+
}
1943
});
2044
}, 10000);
2145
});

0 commit comments

Comments
 (0)