Skip to content

Commit

Permalink
Refactor and update unit-tests (#418)
Browse files Browse the repository at this point in the history
* Update unit-tests and dotnet-install scripts
  • Loading branch information
IvanZosimov authored May 15, 2023
1 parent fc8786b commit 0f534f5
Show file tree
Hide file tree
Showing 9 changed files with 867 additions and 641 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Clear toolcache
shell: pwsh
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
- name: Setup dotnet 2.2.402 and 3.1.404
- name: Setup dotnet 2.2.402, 3.1.404 and 3.0.x
uses: ./
with:
dotnet-version: |
Expand Down
22 changes: 11 additions & 11 deletions __tests__/__snapshots__/authutil.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`authutil tests Existing config not in repo root, sets up a partial NuGet.config user/PAT for GPR 1`] = `
exports[`authutil tests existing config not in repo root, sets up a partial NuGet.config user/PAT for GPR 1`] = `
"<?xml version=\\"1.0\\"?>
<configuration>
<config>
Expand All @@ -15,7 +15,7 @@ exports[`authutil tests Existing config not in repo root, sets up a partial NuGe
</configuration>"
`;
exports[`authutil tests Existing config w/ Azure Artifacts source and NuGet.org, sets up a partial NuGet.config user/PAT for GPR 1`] = `
exports[`authutil tests existing config w/ Azure Artifacts source and NuGet.org, sets up a partial NuGet.config user/PAT for GPR 1`] = `
"<?xml version=\\"1.0\\"?>
<configuration>
<config>
Expand All @@ -30,7 +30,7 @@ exports[`authutil tests Existing config w/ Azure Artifacts source and NuGet.org,
</configuration>"
`;
exports[`authutil tests Existing config w/ GPR source and NuGet.org, sets up a partial NuGet.config user/PAT for GPR 1`] = `
exports[`authutil tests existing config w/ GPR source and NuGet.org, sets up a partial NuGet.config user/PAT for GPR 1`] = `
"<?xml version=\\"1.0\\"?>
<configuration>
<config>
Expand All @@ -45,7 +45,7 @@ exports[`authutil tests Existing config w/ GPR source and NuGet.org, sets up a p
</configuration>"
`;
exports[`authutil tests Existing config w/ no GPR sources, sets up a full NuGet.config with URL and user/PAT for GPR 1`] = `
exports[`authutil tests existing config w/ no GPR sources, sets up a full NuGet.config with URL and user/PAT for GPR 1`] = `
"<?xml version=\\"1.0\\"?>
<configuration>
<config>
Expand All @@ -63,7 +63,7 @@ exports[`authutil tests Existing config w/ no GPR sources, sets up a full NuGet.
</configuration>"
`;
exports[`authutil tests Existing config w/ no sources, sets up a full NuGet.config with URL and user/PAT for GPR 1`] = `
exports[`authutil tests existing config w/ no sources, sets up a full NuGet.config with URL and user/PAT for GPR 1`] = `
"<?xml version=\\"1.0\\"?>
<configuration>
<config>
Expand All @@ -81,7 +81,7 @@ exports[`authutil tests Existing config w/ no sources, sets up a full NuGet.conf
</configuration>"
`;
exports[`authutil tests Existing config w/ only Azure Artifacts source, sets up a partial NuGet.config user/PAT for GPR 1`] = `
exports[`authutil tests existing config w/ only Azure Artifacts source, sets up a partial NuGet.config user/PAT for GPR 1`] = `
"<?xml version=\\"1.0\\"?>
<configuration>
<config>
Expand All @@ -96,7 +96,7 @@ exports[`authutil tests Existing config w/ only Azure Artifacts source, sets up
</configuration>"
`;
exports[`authutil tests Existing config w/ only GPR source, sets up a partial NuGet.config user/PAT for GPR 1`] = `
exports[`authutil tests existing config w/ only GPR source, sets up a partial NuGet.config user/PAT for GPR 1`] = `
"<?xml version=\\"1.0\\"?>
<configuration>
<config>
Expand All @@ -111,7 +111,7 @@ exports[`authutil tests Existing config w/ only GPR source, sets up a partial Nu
</configuration>"
`;
exports[`authutil tests Existing config w/ two GPR sources, sets up a partial NuGet.config user/PAT for GPR 1`] = `
exports[`authutil tests existing config w/ two GPR sources, sets up a partial NuGet.config user/PAT for GPR 1`] = `
"<?xml version=\\"1.0\\"?>
<configuration>
<config>
Expand All @@ -130,7 +130,7 @@ exports[`authutil tests Existing config w/ two GPR sources, sets up a partial Nu
</configuration>"
`;
exports[`authutil tests No existing config, sets up a full NuGet.config with URL and other owner/PAT for GPR 1`] = `
exports[`authutil tests no existing config, sets up a full NuGet.config with URL and other owner/PAT for GPR 1`] = `
"<?xml version=\\"1.0\\"?>
<configuration>
<config>
Expand All @@ -148,7 +148,7 @@ exports[`authutil tests No existing config, sets up a full NuGet.config with URL
</configuration>"
`;
exports[`authutil tests No existing config, sets up a full NuGet.config with URL and token for other source 1`] = `
exports[`authutil tests no existing config, sets up a full NuGet.config with URL and token for other source 1`] = `
"<?xml version=\\"1.0\\"?>
<configuration>
<config>
Expand All @@ -166,7 +166,7 @@ exports[`authutil tests No existing config, sets up a full NuGet.config with URL
</configuration>"
`;
exports[`authutil tests No existing config, sets up a full NuGet.config with URL and user/PAT for GPR 1`] = `
exports[`authutil tests no existing config, sets up a full NuGet.config with URL and user/PAT for GPR 1`] = `
"<?xml version=\\"1.0\\"?>
<configuration>
<config>
Expand Down
56 changes: 28 additions & 28 deletions __tests__/authutil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ describe('authutil tests', () => {
process.env['NUGET_AUTH_TOKEN'] = '';
});

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

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

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

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

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

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

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

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

it('Existing config w/ two GPR sources, sets up a partial NuGet.config user/PAT for GPR', async () => {
it('existing config w/ two GPR sources, sets up a partial NuGet.config user/PAT for GPR', async () => {
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
const inputNuGetConfigPath: string = path.join(
fakeSourcesDirForTesting,
'nuget.config'
);
fs.writeFileSync(inputNuGetConfigPath, twogprNuGetConfig);
await auth.configAuthentication(
auth.configAuthentication(
'https://nuget.pkg.github.com',
'',
fakeSourcesDirForTesting
Expand All @@ -242,7 +242,7 @@ describe('authutil tests', () => {
).toMatchSnapshot();
});

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

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

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

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

it('No existing config, sets up a full NuGet.config with URL and token for other source', async () => {
it('no existing config, sets up a full NuGet.config with URL and token for other source', async () => {
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
await auth.configAuthentication(
auth.configAuthentication(
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
'',
fakeSourcesDirForTesting
Expand Down
42 changes: 33 additions & 9 deletions __tests__/csc.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,45 @@
import cscFile from '../.github/csc.json';
describe('csc tests', () => {
it('Valid regular expression', async () => {
const regex = cscFile['problemMatcher'][0]['pattern'][0]['regexp'];
test('regular expression in csc.json is valid', async () => {
const regexPattern = cscFile['problemMatcher'][0]['pattern'][0]['regexp'];
const regexResultsMap = cscFile['problemMatcher'][0]['pattern'][0];

console.log(regex);
const re = new RegExp(regex);
const regex = new RegExp(regexPattern);

// Ideally we would verify that this
const stringsToMatch = [
'Program.cs(10,79): error CS1002: ; expected [/Users/zacharyeisinger/Documents/repo/setup-dotnet/__tests__/sample-broken-csproj/sample.csproj]',
"S:\\Msbuild\\src\\Build\\Evaluation\\ExpressionShredder.cs(33,7): error CS1003: Syntax error, ',' expected [S:\\msbuild\\src\\Build\\Microsoft.Build.csproj > Properties:prop]"
];
// Expected results are calculated according to the csc matcher located in csc.json file
const expectedResults = [
{
file: 'Program.cs',
line: '10',
severity: 'error',
code: 'CS1002',
message: '; expected',
fromPath:
'/Users/zacharyeisinger/Documents/repo/setup-dotnet/__tests__/sample-broken-csproj/sample.csproj'
},
{
file: 'S:\\Msbuild\\src\\Build\\Evaluation\\ExpressionShredder.cs',
line: '33',
severity: 'error',
code: 'CS1003',
message: "Syntax error, ',' expected",
fromPath:
'S:\\msbuild\\src\\Build\\Microsoft.Build.csproj > Properties:prop'
}
];

stringsToMatch.forEach(string => {
const matchStr = string.match(re);
console.log(matchStr);
expect(matchStr).toEqual(expect.anything());
stringsToMatch.map((string, index) => {
const matchedResultsArray = string.match(regex);
for (const propName in expectedResults[index]) {
const propertyIndex = regexResultsMap[propName];
const expectedPropValue = expectedResults[index][propName];
const matchedPropValue = matchedResultsArray![propertyIndex];
expect(matchedPropValue).toEqual(expectedPropValue);
}
});
}, 10000);
});
Loading

0 comments on commit 0f534f5

Please sign in to comment.