Make tests path separator independent and work on Windows

Signed-off-by: Oliver Sand <oliver.sand@sda-se.com>
This commit is contained in:
Oliver Sand
2021-04-14 15:41:27 +02:00
parent b42531cfed
commit 2fc0c9b1c0
2 changed files with 15 additions and 9 deletions
@@ -15,6 +15,7 @@
*/
import { ConfigReader } from '@backstage/config';
import path from 'path';
import {
buildSqliteDatabaseConfig,
createSqliteDatabaseClient,
@@ -34,9 +35,11 @@ describe('sqlite3', () => {
});
it('builds a persistent connection, normalize config with filename', () => {
expect(buildSqliteDatabaseConfig(createConfig('/path/to/foo'))).toEqual({
expect(
buildSqliteDatabaseConfig(createConfig(path.join('path', 'to', 'foo'))),
).toEqual({
client: 'sqlite3',
connection: { filename: '/path/to/foo' },
connection: { filename: path.join('path', 'to', 'foo') },
useNullAsDefault: true,
});
});
@@ -45,13 +48,13 @@ describe('sqlite3', () => {
expect(
buildSqliteDatabaseConfig(
createConfig({
filename: '/path/to/foo',
filename: path.join('path', 'to', 'foo'),
}),
),
).toEqual({
client: 'sqlite3',
connection: {
filename: '/path/to/foo',
filename: path.join('path', 'to', 'foo'),
},
useNullAsDefault: true,
});
@@ -61,7 +64,7 @@ describe('sqlite3', () => {
expect(
buildSqliteDatabaseConfig(
createConfig({
filename: '/path/to/foo',
filename: path.join('path', 'to', 'foo'),
}),
{
connection: {
@@ -72,7 +75,7 @@ describe('sqlite3', () => {
).toEqual({
client: 'sqlite3',
connection: {
filename: '/path/to/foo/my-database.sqlite',
filename: path.join('path', 'to', 'foo', 'my-database.sqlite'),
database: 'my-database',
},
useNullAsDefault: true,
@@ -82,12 +85,12 @@ describe('sqlite3', () => {
it('replaces the connection with an override', () => {
expect(
buildSqliteDatabaseConfig(createConfig(':memory:'), {
connection: { filename: '/path/to/foo' },
connection: { filename: path.join('path', 'to', 'foo') },
}),
).toEqual({
client: 'sqlite3',
connection: {
filename: '/path/to/foo',
filename: path.join('path', 'to', 'foo'),
},
useNullAsDefault: true,
});
@@ -87,7 +87,10 @@ export function buildSqliteDatabaseConfig(
const sqliteConnection = config.connection as Knex.Sqlite3ConnectionConfig;
if (database && sqliteConnection.filename !== ':memory:') {
sqliteConnection.filename = `${sqliteConnection.filename}/${database}.sqlite`;
sqliteConnection.filename = path.join(
sqliteConnection.filename,
`${database}.sqlite`,
);
}
}