mirror of
https://github.com/actions/setup-dotnet.git
synced 2025-04-06 07:19:55 +00:00
Merge remote-tracking branch 'origin/master' into global-json
This commit is contained in:
185
__tests__/__snapshots__/authutil.test.ts.snap
Normal file
185
__tests__/__snapshots__/authutil.test.ts.snap
Normal file
@ -0,0 +1,185 @@
|
||||
// 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`] = `
|
||||
"<?xml version=\\"1.0\\"?>
|
||||
<configuration>
|
||||
<config>
|
||||
<add key=\\"defaultPushSource\\" value=\\"https://nuget.pkg.github.com/OwnerName/index.json\\"/>
|
||||
</config>
|
||||
<packageSourceCredentials>
|
||||
<GPR>
|
||||
<add key=\\"Username\\" value=\\"OwnerName\\"/>
|
||||
<add key=\\"ClearTextPassword\\" value=\\"TEST_FAKE_AUTH_TOKEN\\"/>
|
||||
</GPR>
|
||||
</packageSourceCredentials>
|
||||
</configuration>"
|
||||
`;
|
||||
|
||||
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>
|
||||
<add key=\\"defaultPushSource\\" value=\\"https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json\\"/>
|
||||
</config>
|
||||
<packageSourceCredentials>
|
||||
<AzureArtifacts>
|
||||
<add key=\\"Username\\" value=\\"OwnerName\\"/>
|
||||
<add key=\\"ClearTextPassword\\" value=\\"TEST_FAKE_AUTH_TOKEN\\"/>
|
||||
</AzureArtifacts>
|
||||
</packageSourceCredentials>
|
||||
</configuration>"
|
||||
`;
|
||||
|
||||
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>
|
||||
<add key=\\"defaultPushSource\\" value=\\"https://nuget.pkg.github.com/OwnerName/index.json\\"/>
|
||||
</config>
|
||||
<packageSourceCredentials>
|
||||
<GPR>
|
||||
<add key=\\"Username\\" value=\\"OwnerName\\"/>
|
||||
<add key=\\"ClearTextPassword\\" value=\\"TEST_FAKE_AUTH_TOKEN\\"/>
|
||||
</GPR>
|
||||
</packageSourceCredentials>
|
||||
</configuration>"
|
||||
`;
|
||||
|
||||
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>
|
||||
<add key=\\"defaultPushSource\\" value=\\"https://nuget.pkg.github.com/OwnerName/index.json\\"/>
|
||||
</config>
|
||||
<packageSources>
|
||||
<add key=\\"Source\\" value=\\"https://nuget.pkg.github.com/OwnerName/index.json\\"/>
|
||||
</packageSources>
|
||||
<packageSourceCredentials>
|
||||
<Source>
|
||||
<add key=\\"Username\\" value=\\"OwnerName\\"/>
|
||||
<add key=\\"ClearTextPassword\\" value=\\"TEST_FAKE_AUTH_TOKEN\\"/>
|
||||
</Source>
|
||||
</packageSourceCredentials>
|
||||
</configuration>"
|
||||
`;
|
||||
|
||||
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>
|
||||
<add key=\\"defaultPushSource\\" value=\\"https://nuget.pkg.github.com/OwnerName/index.json\\"/>
|
||||
</config>
|
||||
<packageSources>
|
||||
<add key=\\"Source\\" value=\\"https://nuget.pkg.github.com/OwnerName/index.json\\"/>
|
||||
</packageSources>
|
||||
<packageSourceCredentials>
|
||||
<Source>
|
||||
<add key=\\"Username\\" value=\\"OwnerName\\"/>
|
||||
<add key=\\"ClearTextPassword\\" value=\\"TEST_FAKE_AUTH_TOKEN\\"/>
|
||||
</Source>
|
||||
</packageSourceCredentials>
|
||||
</configuration>"
|
||||
`;
|
||||
|
||||
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>
|
||||
<add key=\\"defaultPushSource\\" value=\\"https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json\\"/>
|
||||
</config>
|
||||
<packageSourceCredentials>
|
||||
<AzureArtifacts>
|
||||
<add key=\\"Username\\" value=\\"OwnerName\\"/>
|
||||
<add key=\\"ClearTextPassword\\" value=\\"TEST_FAKE_AUTH_TOKEN\\"/>
|
||||
</AzureArtifacts>
|
||||
</packageSourceCredentials>
|
||||
</configuration>"
|
||||
`;
|
||||
|
||||
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>
|
||||
<add key=\\"defaultPushSource\\" value=\\"https://nuget.pkg.github.com/OwnerName/index.json\\"/>
|
||||
</config>
|
||||
<packageSourceCredentials>
|
||||
<GPR>
|
||||
<add key=\\"Username\\" value=\\"OwnerName\\"/>
|
||||
<add key=\\"ClearTextPassword\\" value=\\"TEST_FAKE_AUTH_TOKEN\\"/>
|
||||
</GPR>
|
||||
</packageSourceCredentials>
|
||||
</configuration>"
|
||||
`;
|
||||
|
||||
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>
|
||||
<add key=\\"defaultPushSource\\" value=\\"https://nuget.pkg.github.com\\"/>
|
||||
</config>
|
||||
<packageSourceCredentials>
|
||||
<GPR-GitHub>
|
||||
<add key=\\"Username\\" value=\\"OwnerName\\"/>
|
||||
<add key=\\"ClearTextPassword\\" value=\\"TEST_FAKE_AUTH_TOKEN\\"/>
|
||||
</GPR-GitHub>
|
||||
<GPR-Actions>
|
||||
<add key=\\"Username\\" value=\\"OwnerName\\"/>
|
||||
<add key=\\"ClearTextPassword\\" value=\\"TEST_FAKE_AUTH_TOKEN\\"/>
|
||||
</GPR-Actions>
|
||||
</packageSourceCredentials>
|
||||
</configuration>"
|
||||
`;
|
||||
|
||||
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>
|
||||
<add key=\\"defaultPushSource\\" value=\\"https://nuget.pkg.github.com/otherorg/index.json\\"/>
|
||||
</config>
|
||||
<packageSources>
|
||||
<add key=\\"Source\\" value=\\"https://nuget.pkg.github.com/otherorg/index.json\\"/>
|
||||
</packageSources>
|
||||
<packageSourceCredentials>
|
||||
<Source>
|
||||
<add key=\\"Username\\" value=\\"otherorg\\"/>
|
||||
<add key=\\"ClearTextPassword\\" value=\\"TEST_FAKE_AUTH_TOKEN\\"/>
|
||||
</Source>
|
||||
</packageSourceCredentials>
|
||||
</configuration>"
|
||||
`;
|
||||
|
||||
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>
|
||||
<add key=\\"defaultPushSource\\" value=\\"https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json\\"/>
|
||||
</config>
|
||||
<packageSources>
|
||||
<add key=\\"Source\\" value=\\"https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json\\"/>
|
||||
</packageSources>
|
||||
<packageSourceCredentials>
|
||||
<Source>
|
||||
<add key=\\"Username\\" value=\\"OwnerName\\"/>
|
||||
<add key=\\"ClearTextPassword\\" value=\\"TEST_FAKE_AUTH_TOKEN\\"/>
|
||||
</Source>
|
||||
</packageSourceCredentials>
|
||||
</configuration>"
|
||||
`;
|
||||
|
||||
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>
|
||||
<add key=\\"defaultPushSource\\" value=\\"https://nuget.pkg.github.com/OwnerName/index.json\\"/>
|
||||
</config>
|
||||
<packageSources>
|
||||
<add key=\\"Source\\" value=\\"https://nuget.pkg.github.com/OwnerName/index.json\\"/>
|
||||
</packageSources>
|
||||
<packageSourceCredentials>
|
||||
<Source>
|
||||
<add key=\\"Username\\" value=\\"OwnerName\\"/>
|
||||
<add key=\\"ClearTextPassword\\" value=\\"TEST_FAKE_AUTH_TOKEN\\"/>
|
||||
</Source>
|
||||
</packageSourceCredentials>
|
||||
</configuration>"
|
||||
`;
|
308
__tests__/authutil.test.ts
Normal file
308
__tests__/authutil.test.ts
Normal file
@ -0,0 +1,308 @@
|
||||
import io = require('@actions/io');
|
||||
import fs = require('fs');
|
||||
import path = require('path');
|
||||
|
||||
const fakeSourcesDirForTesting = path.join(
|
||||
__dirname,
|
||||
'runner',
|
||||
path.join(
|
||||
Math.random()
|
||||
.toString(36)
|
||||
.substring(7)
|
||||
),
|
||||
's'
|
||||
);
|
||||
|
||||
const invalidNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>`;
|
||||
|
||||
const emptyNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
</configuration>`;
|
||||
|
||||
const nugetorgNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||||
</packageSources>
|
||||
</configuration>`;
|
||||
|
||||
const gprnugetorgNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<add key="GPR" value="https://nuget.pkg.github.com/OwnerName/index.json" protocolVersion="3" />
|
||||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||||
</packageSources>
|
||||
</configuration>`;
|
||||
|
||||
const gprNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<add key="GPR" value="https://nuget.pkg.github.com/OwnerName/index.json" protocolVersion="3" />
|
||||
</packageSources>
|
||||
</configuration>`;
|
||||
|
||||
const twogprNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<add key="GPR-GitHub" value="https://nuget.pkg.github.com/OwnerName/index.json" protocolVersion="3" />
|
||||
<add key="GPR-Actions" value="https://nuget.pkg.github.com/actions/index.json" protocolVersion="3" />
|
||||
</packageSources>
|
||||
</configuration>`;
|
||||
|
||||
const spaceNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<add key="GPR GitHub" value="https://nuget.pkg.github.com/OwnerName/index.json" protocolVersion="3" />
|
||||
</packageSources>
|
||||
</configuration>`;
|
||||
|
||||
const azureartifactsNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<add key="AzureArtifacts" value="https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json" protocolVersion="3" />
|
||||
</packageSources>
|
||||
</configuration>`;
|
||||
|
||||
const azureartifactsnugetorgNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<add key="AzureArtifacts" value="https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json" protocolVersion="3" />
|
||||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||||
</packageSources>
|
||||
</configuration>`;
|
||||
|
||||
// We want a NuGet.config one level above the sources directory, so it doesn't trample a user's NuGet.config but is still picked up by NuGet/dotnet.
|
||||
const nugetConfigFile = path.join(fakeSourcesDirForTesting, '../nuget.config');
|
||||
|
||||
process.env['GITHUB_REPOSITORY'] = 'OwnerName/repo';
|
||||
process.env['RUNNER_TEMP'] = fakeSourcesDirForTesting;
|
||||
import * as auth from '../src/authutil';
|
||||
|
||||
describe('authutil tests', () => {
|
||||
beforeEach(async () => {
|
||||
await io.rmRF(fakeSourcesDirForTesting);
|
||||
await io.mkdirP(fakeSourcesDirForTesting);
|
||||
}, 100000);
|
||||
|
||||
beforeEach(() => {
|
||||
if (fs.existsSync(nugetConfigFile)) {
|
||||
fs.unlinkSync(nugetConfigFile);
|
||||
}
|
||||
process.env['INPUT_OWNER'] = '';
|
||||
process.env['NUGET_AUTH_TOKEN'] = '';
|
||||
});
|
||||
|
||||
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(
|
||||
'https://nuget.pkg.github.com/OwnerName/index.json'
|
||||
);
|
||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||
expect(
|
||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('No existing config, auth token environment variable not provided, throws', async () => {
|
||||
let thrown = false;
|
||||
try {
|
||||
await auth.configAuthentication(
|
||||
'https://nuget.pkg.github.com/OwnerName/index.json'
|
||||
);
|
||||
} catch {
|
||||
thrown = true;
|
||||
}
|
||||
expect(thrown).toBe(true);
|
||||
});
|
||||
|
||||
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(
|
||||
'https://nuget.pkg.github.com/otherorg/index.json'
|
||||
);
|
||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||
expect(
|
||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
|
||||
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,
|
||||
'nuget.config'
|
||||
);
|
||||
fs.writeFileSync(inputNuGetConfigPath, invalidNuGetConfig);
|
||||
let thrown = false;
|
||||
try {
|
||||
await auth.configAuthentication(
|
||||
'https://nuget.pkg.github.com/OwnerName/index.json'
|
||||
);
|
||||
} catch {
|
||||
thrown = true;
|
||||
}
|
||||
expect(thrown).toBe(true);
|
||||
});
|
||||
|
||||
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(
|
||||
'https://nuget.pkg.github.com/OwnerName/index.json'
|
||||
);
|
||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||
expect(
|
||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
|
||||
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(
|
||||
'https://nuget.pkg.github.com/OwnerName/index.json'
|
||||
);
|
||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||
expect(
|
||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
|
||||
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(
|
||||
'https://nuget.pkg.github.com/OwnerName/index.json'
|
||||
);
|
||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||
expect(
|
||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
|
||||
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(
|
||||
'https://nuget.pkg.github.com/OwnerName/index.json'
|
||||
);
|
||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||
expect(
|
||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
|
||||
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('https://nuget.pkg.github.com');
|
||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||
expect(
|
||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
|
||||
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,
|
||||
'nuget.config'
|
||||
);
|
||||
fs.writeFileSync(inputNuGetConfigPath, spaceNuGetConfig);
|
||||
let thrown = false;
|
||||
try {
|
||||
await auth.configAuthentication(
|
||||
'https://nuget.pkg.github.com/OwnerName/index.json'
|
||||
);
|
||||
} catch {
|
||||
thrown = true;
|
||||
}
|
||||
expect(thrown).toBe(true);
|
||||
});
|
||||
|
||||
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,
|
||||
'subfolder'
|
||||
);
|
||||
const inputNuGetConfigPath: string = path.join(
|
||||
inputNuGetConfigDirectory,
|
||||
'nuget.config'
|
||||
);
|
||||
fs.mkdirSync(inputNuGetConfigDirectory, {recursive: true});
|
||||
fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig);
|
||||
await auth.configAuthentication(
|
||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||
'subfolder/nuget.config'
|
||||
);
|
||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||
expect(
|
||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
|
||||
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(
|
||||
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json'
|
||||
);
|
||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||
expect(
|
||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
|
||||
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(
|
||||
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json'
|
||||
);
|
||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||
expect(
|
||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
|
||||
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(
|
||||
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json'
|
||||
);
|
||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||
expect(
|
||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
});
|
@ -2,7 +2,7 @@ import io = require('@actions/io');
|
||||
import fs = require('fs');
|
||||
import os = require('os');
|
||||
import path = require('path');
|
||||
import httpClient = require('typed-rest-client/HttpClient');
|
||||
import hc = require('@actions/http-client');
|
||||
|
||||
const toolDir = path.join(__dirname, 'runner', 'tools');
|
||||
const tempDir = path.join(__dirname, 'runner', 'temp');
|
||||
@ -30,8 +30,8 @@ describe('installer tests', () => {
|
||||
}, 100000);
|
||||
|
||||
it('Acquires version of dotnet if no matching version is installed', async () => {
|
||||
await getDotnet('2.2.104');
|
||||
const dotnetDir = path.join(toolDir, 'dncs', '2.2.104', os.arch());
|
||||
await getDotnet('2.2.205');
|
||||
const dotnetDir = path.join(toolDir, 'dncs', '2.2.205', os.arch());
|
||||
|
||||
expect(fs.existsSync(`${dotnetDir}.complete`)).toBe(true);
|
||||
if (IS_WINDOWS) {
|
||||
@ -94,14 +94,14 @@ describe('installer tests', () => {
|
||||
});
|
||||
|
||||
it('Uses an up to date bash download script', async () => {
|
||||
var httpCallbackClient = new httpClient.HttpClient(
|
||||
'setup-dotnet-test',
|
||||
[],
|
||||
{}
|
||||
);
|
||||
const response: httpClient.HttpClientResponse = await httpCallbackClient.get(
|
||||
const httpCallbackClient = new hc.HttpClient('setup-dotnet-test', [], {
|
||||
allowRetries: true,
|
||||
maxRetries: 3
|
||||
});
|
||||
const response: hc.HttpClientResponse = await httpCallbackClient.get(
|
||||
'https://dot.net/v1/dotnet-install.sh'
|
||||
);
|
||||
expect(response.message.statusCode).toBe(200);
|
||||
const upToDateContents: string = await response.readBody();
|
||||
const currentContents: string = fs
|
||||
.readFileSync(
|
||||
@ -111,17 +111,17 @@ describe('installer tests', () => {
|
||||
expect(normalizeFileContents(currentContents)).toBe(
|
||||
normalizeFileContents(upToDateContents)
|
||||
);
|
||||
});
|
||||
}, 100000);
|
||||
|
||||
it('Uses an up to date powershell download script', async () => {
|
||||
var httpCallbackClient = new httpClient.HttpClient(
|
||||
'setup-dotnet-test',
|
||||
[],
|
||||
{}
|
||||
);
|
||||
const response: httpClient.HttpClientResponse = await httpCallbackClient.get(
|
||||
var httpCallbackClient = new hc.HttpClient('setup-dotnet-test', [], {
|
||||
allowRetries: true,
|
||||
maxRetries: 3
|
||||
});
|
||||
const response: hc.HttpClientResponse = await httpCallbackClient.get(
|
||||
'https://dot.net/v1/dotnet-install.ps1'
|
||||
);
|
||||
expect(response.message.statusCode).toBe(200);
|
||||
const upToDateContents: string = await response.readBody();
|
||||
const currentContents: string = fs
|
||||
.readFileSync(
|
||||
@ -131,7 +131,7 @@ describe('installer tests', () => {
|
||||
expect(normalizeFileContents(currentContents)).toBe(
|
||||
normalizeFileContents(upToDateContents)
|
||||
);
|
||||
});
|
||||
}, 100000);
|
||||
});
|
||||
|
||||
function normalizeFileContents(contents: string): string {
|
||||
|
14
__tests__/sample-csproj/Program.cs
Normal file
14
__tests__/sample-csproj/Program.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace sample_csproj
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(new[] {"Hello", "World!" });
|
||||
Console.WriteLine(json);
|
||||
}
|
||||
}
|
||||
}
|
7
__tests__/sample-csproj/runtimeconfig.template.json
Normal file
7
__tests__/sample-csproj/runtimeconfig.template.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"runtimeOptions": {
|
||||
"configProperties": {
|
||||
"System.Globalization.Invariant": true
|
||||
}
|
||||
}
|
||||
}
|
13
__tests__/sample-csproj/sample.csproj
Normal file
13
__tests__/sample-csproj/sample.csproj
Normal file
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<RootNamespace>sample_csproj</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
32
__tests__/verify-dotnet.ps1
Executable file
32
__tests__/verify-dotnet.ps1
Executable file
@ -0,0 +1,32 @@
|
||||
if (!$args[0])
|
||||
{
|
||||
throw "Must supply dotnet version argument"
|
||||
}
|
||||
|
||||
$dotnet = Get-Command dotnet | Select-Object -First 1 | ForEach-Object { $_.Path }
|
||||
Write-Host "Found '$dotnet'"
|
||||
|
||||
$version = & $dotnet --version | Out-String | ForEach-Object { $_.Trim() }
|
||||
Write-Host "Version $version"
|
||||
# if ($version -ne $args[0])
|
||||
# {
|
||||
# Write-Host "PATH='$env:path'"
|
||||
# Write-Host "gcm dotnet:"
|
||||
# gcm dotnet | fl
|
||||
# throw "Unexpected version"
|
||||
# }
|
||||
|
||||
Write-Host "Building sample csproj"
|
||||
& $dotnet build __tests__/sample-csproj/ --no-cache
|
||||
if ($LASTEXITCODE -ne 0)
|
||||
{
|
||||
throw "Unexpected exit code $LASTEXITCODE"
|
||||
}
|
||||
|
||||
Write-Host "Testing compiled app"
|
||||
$sample_output = "$(__tests__/sample-csproj/bin/Debug/netcoreapp3.0/sample.exe)".Trim()
|
||||
Write-Host "Sample output: $sample_output"
|
||||
if ($sample_output -notlike "*Hello*World*")
|
||||
{
|
||||
throw "Unexpected output"
|
||||
}
|
22
__tests__/verify-dotnet.sh
Executable file
22
__tests__/verify-dotnet.sh
Executable file
@ -0,0 +1,22 @@
|
||||
if [ -z "$1" ]; then
|
||||
echo "Must supply dotnet version argument"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
dotnet_version="$(dotnet --version)"
|
||||
echo "Found dotnet version '$dotnet_version'"
|
||||
if [ -z "$(echo $dotnet_version | grep $1)" ]; then
|
||||
echo "Unexpected version"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Building sample csproj"
|
||||
dotnet build __tests__/sample-csproj/ --no-cache || exit 1
|
||||
|
||||
echo "Testing compiled app"
|
||||
sample_output="$(__tests__/sample-csproj/bin/Debug/netcoreapp3.0/sample)"
|
||||
echo "Sample output: $sample_output"
|
||||
if [ -z "$(echo $sample_output | grep Hello)" ]; then
|
||||
echo "Unexpected output"
|
||||
exit 1
|
||||
fi
|
17
__tests__/verify-no-unstaged-changes.sh
Executable file
17
__tests__/verify-no-unstaged-changes.sh
Executable file
@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ "$(git status --porcelain)" != "" ]]; then
|
||||
echo ----------------------------------------
|
||||
echo git status
|
||||
echo ----------------------------------------
|
||||
git status
|
||||
echo ----------------------------------------
|
||||
echo git diff
|
||||
echo ----------------------------------------
|
||||
git diff
|
||||
echo ----------------------------------------
|
||||
echo Troubleshooting
|
||||
echo ----------------------------------------
|
||||
echo "::error::Unstaged changes detected. Locally try running: git clean -ffdx && npm ci && npm run pre-checkin"
|
||||
exit 1
|
||||
fi
|
Reference in New Issue
Block a user