Skip to content

[INTERNAL] ReaderCollection: Add tests for duplicate resources #150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: v2
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions test/lib/ReaderCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,86 @@ test("ReaderCollection: _byGlob with finding a resource", (t) => {
});
});

test("ReaderCollection: _byGlob with duplicate resources", async (t) => {
const resource1 = new Resource({
path: "my/path",
buffer: Buffer.from("content")
});

const resource2 = new Resource({
path: "my/path",
buffer: Buffer.from("content")
});
const abstractReader1 = {
_byGlob: sinon.stub().returns(Promise.resolve([resource1]))
};
const abstractReader2 = {
_byGlob: sinon.stub().returns(Promise.resolve([resource2]))
};
const trace = {
collection: sinon.spy()
};
const readerCollection = new ReaderCollection({
name: "myReader",
readers: [abstractReader1, abstractReader2]
});

const res = await readerCollection._byGlob("anyPattern", {nodir: true}, trace);
t.deepEqual(res.length, 2, "Two resources found");
t.deepEqual(res[0].getPath(), "my/path", "Resource 1 has expected path");
t.deepEqual(res[1].getPath(), "my/path", "Resource 2 has expected path (same as 1)");
});

test("ReaderCollection: _byGlob with duplicate directories", async (t) => {
const fnTrue = () => true;
const fnFalse = () => false;
const dirStatInfo = {
isFile: fnFalse,
isDirectory: fnTrue,
isBlockDevice: fnFalse,
isCharacterDevice: fnFalse,
isSymbolicLink: fnFalse,
isFIFO: fnFalse,
isSocket: fnFalse,
atimeMs: new Date().getTime(),
mtimeMs: new Date().getTime(),
ctimeMs: new Date().getTime(),
birthtimeMs: new Date().getTime(),
atime: new Date(),
mtime: new Date(),
ctime: new Date(),
birthtime: new Date()
};

const resource1 = new Resource({
path: "my/dir",
statInfo: dirStatInfo
});

const resource2 = new Resource({
path: "my/dir",
statInfo: dirStatInfo
});
const abstractReader1 = {
_byGlob: sinon.stub().returns(Promise.resolve([resource1]))
};
const abstractReader2 = {
_byGlob: sinon.stub().returns(Promise.resolve([resource2]))
};
const trace = {
collection: sinon.spy()
};
const readerCollection = new ReaderCollection({
name: "myReader",
readers: [abstractReader1, abstractReader2]
});

const res = await readerCollection._byGlob("anyPattern", {nodir: true}, trace);
t.deepEqual(res.length, 2, "Two resources found");
t.deepEqual(res[0].getPath(), "my/dir", "Resource 1 has expected path");
t.deepEqual(res[1].getPath(), "my/dir", "Resource 2 has expected path (same as 1)");
});

test("ReaderCollection: _byPath with reader finding a resource", (t) => {
t.plan(5);

Expand Down