Skip to content

Commit

Permalink
[INTERNAL] Fix resources tests
Browse files Browse the repository at this point in the history
Some tests didn't use the corresponding adapter, which caused
race-conditions as both adapter tests used the FileSystem adapter.

It is now ensured that all tests use the right adapter.

Follow-up of #448
  • Loading branch information
matz3 committed Jan 4, 2023
1 parent d5a2464 commit c3a116d
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions test/lib/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,23 @@ test.afterEach.always((t) => {
sinon.restore();
});

const adapters = ["FileSystem", "Memory"];

async function getAdapter(config, adapter) {
if (adapter === "Memory") {
const fsAdapter = createAdapter(config);
const fsResources = await fsAdapter.byGlob("**/*");
// By removing the fsBasePath a MemAdapter will be created
delete config.fsBasePath;
const memAdapter = createAdapter(config);
for (const resource of fsResources) {
await memAdapter.write(resource);
["FileSystem", "Memory"].forEach((adapter) => {
async function getAdapter(config) {
if (adapter === "Memory") {
const fsAdapter = createAdapter(config);
const fsResources = await fsAdapter.byGlob("**/*");
// By removing the fsBasePath a MemAdapter will be created
delete config.fsBasePath;
const memAdapter = createAdapter(config);
for (const resource of fsResources) {
await memAdapter.write(resource);
}
return memAdapter;
} else if (adapter === "FileSystem") {
return createAdapter(config);
}
return memAdapter;
} else {
return createAdapter(config);
}
}

for (const adapter of adapters) {
/* BEWARE:
Always make sure that every test writes to a separate file! By default, tests are running concurrent.
*/
Expand All @@ -38,11 +36,11 @@ for (const adapter of adapters) {
const source = await getAdapter({
fsBasePath: "./test/fixtures/application.a/webapp",
virBasePath: "/app/"
}, adapter);
});
const dest = await getAdapter({
fsBasePath: "./test/tmp/readerWriters/application.a/simple-read-write",
virBasePath: "/dest/"
}, adapter);
});

// Get resource from one readerWriter
const resource = await source.byPath("/app/index.html");
Expand Down Expand Up @@ -170,7 +168,7 @@ for (const adapter of adapters) {
const source = await getAdapter({
fsBasePath: "./test/fixtures/application.a/webapp",
virBasePath: "/resources/app/"
}, adapter);
});
const transformedSource = createFlatReader({
reader: source,
namespace: "app"
Expand All @@ -185,7 +183,7 @@ for (const adapter of adapters) {
const source = await getAdapter({
fsBasePath: "./test/fixtures/application.a/webapp",
virBasePath: "/resources/app/"
}, adapter);
});
const transformedSource = createLinkReader({
reader: source,
pathMapping: {
Expand All @@ -198,4 +196,4 @@ for (const adapter of adapters) {
t.is(resources.length, 1, "Found one resource via transformer");
t.is(resources[0].getPath(), "/wow/this/is/a/beautiful/path/just/wow/app/test.js", "Found correct resource");
});
}
});

0 comments on commit c3a116d

Please sign in to comment.