plugins,packages: replace usages of ConfigReader.from

This commit is contained in:
Patrik Oldsberg
2020-12-15 19:04:50 +01:00
parent a3b2c5a68b
commit 1da7d2c657
34 changed files with 174 additions and 322 deletions
@@ -28,14 +28,9 @@ describe('GithubOrgReaderProcessor', () => {
function config(
providers: { target: string; apiBaseUrl?: string; token?: string }[],
) {
return ConfigReader.fromConfigs([
{
context: '',
data: {
catalog: { processors: { githubOrg: { providers } } },
},
},
]);
return new ConfigReader({
catalog: { processors: { githubOrg: { providers } } },
});
}
it('adds a default GitHub entry when missing', () => {
@@ -32,9 +32,7 @@ describe('readLdapConfig', () => {
},
],
};
const actual = readLdapConfig(
ConfigReader.fromConfigs([{ context: '', data: config }]),
);
const actual = readLdapConfig(new ConfigReader(config));
const expected = [
{
target: 'target',
@@ -125,9 +123,7 @@ describe('readLdapConfig', () => {
},
],
};
const actual = readLdapConfig(
ConfigReader.fromConfigs([{ context: '', data: config }]),
);
const actual = readLdapConfig(new ConfigReader(config));
const expected = [
{
target: 'target',
@@ -29,9 +29,7 @@ describe('readMicrosoftGraphConfig', () => {
},
],
};
const actual = readMicrosoftGraphConfig(
ConfigReader.fromConfigs([{ context: '', data: config }]),
);
const actual = readMicrosoftGraphConfig(new ConfigReader(config));
const expected = [
{
target: 'target',
@@ -60,9 +58,7 @@ describe('readMicrosoftGraphConfig', () => {
},
],
};
const actual = readMicrosoftGraphConfig(
ConfigReader.fromConfigs([{ context: '', data: config }]),
);
const actual = readMicrosoftGraphConfig(new ConfigReader(config));
const expected = [
{
target: 'target',
@@ -47,7 +47,7 @@ describe('CatalogBuilder', () => {
const env: CatalogEnvironment = {
logger: getVoidLogger(),
database: { getClient: async () => db },
config: ConfigReader.fromConfigs([]),
config: new ConfigReader({}),
reader,
};
@@ -27,16 +27,11 @@ import { gql } from 'apollo-server';
describe('Catalog Module', () => {
const worker = setupServer();
const mockCatalogBaseUrl = 'http://im.mock';
const mockConfig = ConfigReader.fromConfigs([
{
context: '',
data: {
backend: {
baseUrl: mockCatalogBaseUrl,
},
},
const mockConfig = new ConfigReader({
backend: {
baseUrl: mockCatalogBaseUrl,
},
]);
});
msw.setupDefaultHandlers(worker);
+1 -3
View File
@@ -22,9 +22,7 @@ import express from 'express';
describe('Router', () => {
describe('/health', () => {
it('should return ok', async () => {
const config = ConfigReader.fromConfigs([
{ data: { backend: { baseUrl: 'lol' } }, context: 'something' },
]);
const config = new ConfigReader({ backend: { baseUrl: 'lol' } });
const router = await createRouter({ config, logger: createLogger() });
const app = express().use(router);
@@ -20,12 +20,9 @@ import { ConfigClusterLocator } from './ConfigClusterLocator';
describe('ConfigClusterLocator', () => {
it('empty clusters returns empty cluster details', async () => {
const config: Config = new ConfigReader(
{
clusters: [],
},
'ctx',
);
const config: Config = new ConfigReader({
clusters: [],
});
const sut = ConfigClusterLocator.fromConfig(
config.getConfigArray('clusters'),
@@ -37,18 +34,15 @@ describe('ConfigClusterLocator', () => {
});
it('one clusters returns one cluster details', async () => {
const config: Config = new ConfigReader(
{
clusters: [
{
name: 'cluster1',
url: 'http://localhost:8080',
authProvider: 'serviceAccount',
},
],
},
'ctx',
);
const config: Config = new ConfigReader({
clusters: [
{
name: 'cluster1',
url: 'http://localhost:8080',
authProvider: 'serviceAccount',
},
],
});
const sut = ConfigClusterLocator.fromConfig(
config.getConfigArray('clusters'),
@@ -67,24 +61,21 @@ describe('ConfigClusterLocator', () => {
});
it('two clusters returns two cluster details', async () => {
const config: Config = new ConfigReader(
{
clusters: [
{
name: 'cluster1',
serviceAccountToken: 'token',
url: 'http://localhost:8080',
authProvider: 'serviceAccount',
},
{
name: 'cluster2',
url: 'http://localhost:8081',
authProvider: 'google',
},
],
},
'ctx',
);
const config: Config = new ConfigReader({
clusters: [
{
name: 'cluster1',
serviceAccountToken: 'token',
url: 'http://localhost:8080',
authProvider: 'serviceAccount',
},
{
name: 'cluster2',
url: 'http://localhost:8081',
authProvider: 'google',
},
],
});
const sut = ConfigClusterLocator.fromConfig(
config.getConfigArray('clusters'),
@@ -60,7 +60,7 @@ describe('getCombinedClusterDetails', () => {
it('throws an error when using an unsupported cluster locator', async () => {
await expect(
getCombinedClusterDetails(['magic' as any], new ConfigReader({}, 'ctx')),
getCombinedClusterDetails(['magic' as any], new ConfigReader({})),
).rejects.toStrictEqual(
new Error('Unsupported kubernetes.clusterLocatorMethods: "magic"'),
);
@@ -36,7 +36,7 @@ export async function createStandaloneApplication(
options: ApplicationOptions,
): Promise<express.Application> {
const { enableCors, logger } = options;
const config = ConfigReader.fromConfigs([]);
const config = new ConfigReader({});
const app = express();
app.use(helmet());
@@ -38,9 +38,7 @@ describe('createRouter', () => {
const router = await createRouter({
rollbarApi,
logger: getVoidLogger(),
config: ConfigReader.fromConfigs([
{ context: 'abc', data: { rollbar: { accountToken: 'foo' } } },
]),
config: new ConfigReader({ rollbar: { accountToken: 'foo' } }),
});
app = express().use(router);
});
@@ -78,7 +78,7 @@ describe('AzurePreparer', () => {
});
it('calls the clone command with the correct arguments for a repository', async () => {
const preparer = new AzurePreparer(ConfigReader.fromConfigs([]));
const preparer = new AzurePreparer(new ConfigReader({}));
await preparer.prepare(mockEntity, { logger: getVoidLogger() });
expect(mocks.Clone.clone).toHaveBeenNthCalledWith(
1,
@@ -90,20 +90,15 @@ describe('AzurePreparer', () => {
it('calls the clone command with the correct arguments if an access token is provided for a repository', async () => {
const preparer = new AzurePreparer(
ConfigReader.fromConfigs([
{
context: '',
data: {
scaffolder: {
azure: {
api: {
token: 'fake-token',
},
},
new ConfigReader({
scaffolder: {
azure: {
api: {
token: 'fake-token',
},
},
},
]),
}),
);
await preparer.prepare(mockEntity, { logger: getVoidLogger() });
expect(mocks.Clone.clone).toHaveBeenNthCalledWith(
@@ -121,7 +116,7 @@ describe('AzurePreparer', () => {
});
it('calls the clone command with the correct arguments for a repository when no path is provided', async () => {
const preparer = new AzurePreparer(ConfigReader.fromConfigs([]));
const preparer = new AzurePreparer(new ConfigReader({}));
delete mockEntity.spec.path;
await preparer.prepare(mockEntity, { logger: getVoidLogger() });
expect(mocks.Clone.clone).toHaveBeenNthCalledWith(
@@ -133,7 +128,7 @@ describe('AzurePreparer', () => {
});
it('return the temp directory with the path to the folder if it is specified', async () => {
const preparer = new AzurePreparer(ConfigReader.fromConfigs([]));
const preparer = new AzurePreparer(new ConfigReader({}));
mockEntity.spec.path = './template/test/1/2/3';
const response = await preparer.prepare(mockEntity, {
logger: getVoidLogger(),
@@ -145,7 +140,7 @@ describe('AzurePreparer', () => {
});
it('return the working directory with the path to the folder if it is specified', async () => {
const preparer = new AzurePreparer(ConfigReader.fromConfigs([]));
const preparer = new AzurePreparer(new ConfigReader({}));
mockEntity.spec.path = './template/test/1/2/3';
const response = await preparer.prepare(mockEntity, {
logger: getVoidLogger(),
@@ -78,7 +78,7 @@ describe('GitLabPreparer', () => {
['gitlab', 'gitlab/api'].forEach(protocol => {
it(`calls the clone command with the correct arguments for a repository using the ${protocol} protocol`, async () => {
const preparer = new GitlabPreparer(ConfigReader.fromConfigs([]));
const preparer = new GitlabPreparer(new ConfigReader({}));
mockEntity = mockEntityWithProtocol(protocol);
await preparer.prepare(mockEntity, { logger: getVoidLogger() });
expect(mocks.Clone.clone).toHaveBeenNthCalledWith(
@@ -91,20 +91,15 @@ describe('GitLabPreparer', () => {
it(`calls the clone command with the correct arguments if an access token is provided for a repository using the ${protocol} protocol`, async () => {
const preparer = new GitlabPreparer(
ConfigReader.fromConfigs([
{
context: '',
data: {
catalog: {
processors: {
gitlabApi: {
privateToken: 'fake-token',
},
},
new ConfigReader({
catalog: {
processors: {
gitlabApi: {
privateToken: 'fake-token',
},
},
},
]),
}),
);
mockEntity = mockEntityWithProtocol(protocol);
await preparer.prepare(mockEntity, { logger: getVoidLogger() });
@@ -123,7 +118,7 @@ describe('GitLabPreparer', () => {
});
it(`calls the clone command with the correct arguments for a repository when no path is provided using the ${protocol} protocol`, async () => {
const preparer = new GitlabPreparer(ConfigReader.fromConfigs([]));
const preparer = new GitlabPreparer(new ConfigReader({}));
mockEntity = mockEntityWithProtocol(protocol);
delete mockEntity.spec.path;
await preparer.prepare(mockEntity, { logger: getVoidLogger() });
@@ -136,7 +131,7 @@ describe('GitLabPreparer', () => {
});
it(`return the temp directory with the path to the folder if it is specified using the ${protocol} protocol`, async () => {
const preparer = new GitlabPreparer(ConfigReader.fromConfigs([]));
const preparer = new GitlabPreparer(new ConfigReader({}));
mockEntity = mockEntityWithProtocol(protocol);
mockEntity.spec.path = './template/test/1/2/3';
const response = await preparer.prepare(mockEntity, {
@@ -149,7 +144,7 @@ describe('GitLabPreparer', () => {
});
it('return the working directory with the path to the folder if it is specified', async () => {
const preparer = new GitlabPreparer(ConfigReader.fromConfigs([]));
const preparer = new GitlabPreparer(new ConfigReader({}));
mockEntity.spec.path = './template/test/1/2/3';
const response = await preparer.prepare(mockEntity, {
logger: getVoidLogger(),
@@ -55,11 +55,8 @@ describe('createRouter - working directory', () => {
});
const workDirConfig = (path: string) => ({
context: '',
data: {
backend: {
workingDirectory: path,
},
backend: {
workingDirectory: path,
},
});
@@ -91,7 +88,7 @@ describe('createRouter - working directory', () => {
preparers: new Preparers(),
templaters: new Templaters(),
publishers: new Publishers(),
config: ConfigReader.fromConfigs([workDirConfig('/path')]),
config: new ConfigReader(workDirConfig('/path')),
dockerClient: new Docker(),
entityClient: mockedEntityClient,
}),
@@ -104,7 +101,7 @@ describe('createRouter - working directory', () => {
preparers: mockPreparers,
templaters: new Templaters(),
publishers: new Publishers(),
config: ConfigReader.fromConfigs([workDirConfig('/path')]),
config: new ConfigReader(workDirConfig('/path')),
dockerClient: new Docker(),
entityClient: mockedEntityClient,
});
@@ -127,7 +124,7 @@ describe('createRouter - working directory', () => {
preparers: mockPreparers,
templaters: new Templaters(),
publishers: new Publishers(),
config: ConfigReader.fromConfigs([]),
config: new ConfigReader({}),
dockerClient: new Docker(),
entityClient: mockedEntityClient,
});
@@ -190,7 +187,7 @@ describe('createRouter', () => {
preparers: new Preparers(),
templaters: new Templaters(),
publishers: new Publishers(),
config: ConfigReader.fromConfigs([]),
config: new ConfigReader({}),
dockerClient: new Docker(),
entityClient: generateEntityClient(template),
});
@@ -41,18 +41,13 @@ export async function startStandaloneServer(
options: ServerOptions,
): Promise<Server> {
const logger = options.logger.child({ service: 'techdocs-backend' });
const config = ConfigReader.fromConfigs([
{
context: '',
data: {
techdocs: {
publisher: {
type: 'local',
},
},
const config = new ConfigReader({
techdocs: {
publisher: {
type: 'local',
},
},
]);
});
const discovery = SingleHostDiscovery.fromConfig(config);
logger.debug('Creating application...');
@@ -37,18 +37,13 @@ const mockGoogleAuth = {
};
const createConfig = () =>
ConfigReader.fromConfigs([
{
context: '',
data: {
auth: {
providers: {
google: { development: {} },
},
},
new ConfigReader({
auth: {
providers: {
google: { development: {} },
},
},
]);
});
const config = createConfig();