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
@@ -21,14 +21,6 @@ import { SingleConnectionDatabaseManager } from './SingleConnection';
jest.mock('./connection');
describe('SingleConnectionDatabaseManager', () => {
const createConfig = (data: any) =>
ConfigReader.fromConfigs([
{
context: '',
data,
},
]);
const defaultConfigOptions = {
backend: {
database: {
@@ -42,7 +34,7 @@ describe('SingleConnectionDatabaseManager', () => {
},
},
};
const defaultConfig = () => createConfig(defaultConfigOptions);
const defaultConfig = () => new ConfigReader(defaultConfigOptions);
// This is similar to the ts-jest `mocked` helper.
const mocked = (f: Function) => f as jest.Mock;
@@ -18,19 +18,11 @@ import { ConfigReader } from '@backstage/config';
import { createDatabaseClient } from './connection';
describe('database connection', () => {
const createConfig = (data: any) =>
ConfigReader.fromConfigs([
{
context: '',
data,
},
]);
describe('createDatabaseClient', () => {
it('returns a postgres connection', () => {
expect(
createDatabaseClient(
createConfig({
new ConfigReader({
client: 'pg',
connection: {
host: 'acme',
@@ -46,7 +38,7 @@ describe('database connection', () => {
it('returns an sqlite connection', () => {
expect(
createDatabaseClient(
createConfig({
new ConfigReader({
client: 'sqlite3',
connection: ':memory:',
}),
@@ -57,7 +49,7 @@ describe('database connection', () => {
it('tries to create a mysql connection as a passthrough', () => {
expect(() =>
createDatabaseClient(
createConfig({
new ConfigReader({
client: 'mysql',
connection: {
host: '127.0.0.1',
@@ -73,7 +65,7 @@ describe('database connection', () => {
it('accepts overrides', () => {
expect(
createDatabaseClient(
createConfig({
new ConfigReader({
client: 'pg',
connection: {
host: 'acme',
@@ -94,7 +86,7 @@ describe('database connection', () => {
it('throws an error without a client', () => {
expect(() =>
createDatabaseClient(
createConfig({
new ConfigReader({
connection: '',
}),
),
@@ -104,7 +96,7 @@ describe('database connection', () => {
it('throws an error without a connection', () => {
expect(() =>
createDatabaseClient(
createConfig({
new ConfigReader({
client: 'pg',
}),
),
@@ -34,15 +34,7 @@ describe('postgres', () => {
'postgresql://foo:bar@acme:5432/foodb';
const createConfig = (connection: any): Config =>
ConfigReader.fromConfigs([
{
context: '',
data: {
client: 'pg',
connection,
},
},
]);
new ConfigReader({ client: 'pg', connection });
describe('buildPgDatabaseConfig', () => {
it('builds a postgres config', () => {
@@ -22,15 +22,7 @@ import {
describe('sqlite3', () => {
const createConfig = (connection: any) =>
ConfigReader.fromConfigs([
{
context: '',
data: {
client: 'sqlite3',
connection,
},
},
]);
new ConfigReader({ client: 'sqlite3', connection });
describe('buildSqliteDatabaseConfig', () => {
it('buidls a string connection', () => {
@@ -20,9 +20,7 @@ import { readCspOptions } from './config';
describe('config', () => {
describe('readCspOptions', () => {
it('reads valid values', () => {
const config = ConfigReader.fromConfigs([
{ context: '', data: { csp: { key: ['value'] } } },
]);
const config = new ConfigReader({ csp: { key: ['value'] } });
expect(readCspOptions(config)).toEqual(
expect.objectContaining({
key: ['value'],
@@ -31,9 +29,7 @@ describe('config', () => {
});
it('accepts false', () => {
const config = ConfigReader.fromConfigs([
{ context: '', data: { csp: { key: false } } },
]);
const config = new ConfigReader({ csp: { key: false } });
expect(readCspOptions(config)).toEqual(
expect.objectContaining({
key: false,
@@ -42,9 +38,7 @@ describe('config', () => {
});
it('rejects invalid value types', () => {
const config = ConfigReader.fromConfigs([
{ context: '', data: { csp: { key: [4] } } },
]);
const config = new ConfigReader({ csp: { key: [4] } });
expect(() => readCspOptions(config)).toThrow(/wanted string-array/);
});
});