Skip to content

Commit

Permalink
[INTERNAL] serveIndex: improved tests with regards to size (#335)
Browse files Browse the repository at this point in the history
Changed tests to use the buffer size for the size display
when serving the index. Will work together with:
SAP/ui5-fs#253
  • Loading branch information
tobiasso85 authored Jul 3, 2020
1 parent 4a8d624 commit 7208a26
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions test/lib/server/middleware/serveIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ const MiddlewareUtil = require("../../../../lib/middleware/MiddlewareUtil");
test.serial("serveIndex default", (t) => {
t.plan(4);
const serveIndexMiddleware = require("../../../../lib/middleware/serveIndex");
const writeResource = function(writer, path, size = 0, stringContent = "abc") {
const writeResource = function(writer, path, buffer) {
const statInfo = {
mtime: 0,
size: size,
size: buffer.byteLength,
isDirectory: function() {
return false;
}
};
const resource = resourceFactory.createResource({statInfo, path, string: stringContent});
const resource = resourceFactory.createResource({statInfo, path, buffer});
return writer.write(resource);
};

const readerWriter = resourceFactory.createAdapter({virBasePath: "/"});

return Promise.all([
writeResource(readerWriter, "/myFile1.meh", 1024), // KB
writeResource(readerWriter, "/myFile2.js", 1024 * 1024), // MB
writeResource(readerWriter, "/myFile3.properties", 1024 * 1024 * 1024), // GB
writeResource(readerWriter, "/.myFile4", 1024), // hidden 1 KB
writeResource(readerWriter, "/myFile1.meh", Buffer.alloc(1024)), // KB
writeResource(readerWriter, "/myFile2.js", Buffer.alloc(1024 * 1024)), // MB
writeResource(readerWriter, "/myFile3.properties", Buffer.alloc(1024 * 1024 * 1024)), // GB
writeResource(readerWriter, "/.myFile4", Buffer.alloc(1024)), // hidden 1 KB
]).then(() => {
const middleware = serveIndexMiddleware({
middlewareUtil: new MiddlewareUtil(),
Expand Down Expand Up @@ -58,25 +58,25 @@ test.serial("serveIndex default", (t) => {
test.serial("serveIndex no hidden", (t) => {
t.plan(4);
const serveIndexMiddleware = require("../../../../lib/middleware/serveIndex");
const writeResource = function(writer, path, size = 0, stringContent = "abc") {
const writeResource = function(writer, path, buffer) {
const statInfo = {
mtime: 0,
size: size,
size: buffer.byteLength,
isDirectory: function() {
return false;
}
};
const resource = resourceFactory.createResource({statInfo, path, string: stringContent});
const resource = resourceFactory.createResource({statInfo, path, buffer});
return writer.write(resource);
};

const readerWriter = resourceFactory.createAdapter({virBasePath: "/"});

return Promise.all([
writeResource(readerWriter, "/myFile1.meh", 1024), // KB
writeResource(readerWriter, "/myFile2.js", 1024 * 1024), // MB
writeResource(readerWriter, "/myFile3.properties", 1024 * 1024 * 1024), // GB
writeResource(readerWriter, "/.myFile4", 1024), // hidden 1 KB
writeResource(readerWriter, "/myFile1.meh", Buffer.alloc(1024)), // KB
writeResource(readerWriter, "/myFile2.js", Buffer.alloc(1024 * 1024)), // MB
writeResource(readerWriter, "/myFile3.properties", Buffer.alloc(1024 * 1024 * 1024)), // GB
writeResource(readerWriter, "/.myFile4", Buffer.alloc(1024)), // hidden 1 KB
]).then(() => {
const middleware = serveIndexMiddleware({
middlewareUtil: new MiddlewareUtil(),
Expand Down Expand Up @@ -113,25 +113,25 @@ test.serial("serveIndex no hidden", (t) => {
test.serial("serveIndex no details", (t) => {
t.plan(4);
const serveIndexMiddleware = require("../../../../lib/middleware/serveIndex");
const writeResource = function(writer, path, size = 0, stringContent = "abc") {
const writeResource = function(writer, path, buffer) {
const statInfo = {
mtime: 0,
size: size,
size: buffer.byteLength,
isDirectory: function() {
return false;
}
};
const resource = resourceFactory.createResource({statInfo, path, string: stringContent});
const resource = resourceFactory.createResource({statInfo, path, buffer});
return writer.write(resource);
};

const readerWriter = resourceFactory.createAdapter({virBasePath: "/"});

return Promise.all([
writeResource(readerWriter, "/myFile1.meh", 1024), // KB
writeResource(readerWriter, "/myFile2.js", 1024 * 1024), // MB
writeResource(readerWriter, "/myFile3.properties", 1024 * 1024 * 1024), // GB
writeResource(readerWriter, "/.myFile4", 1024), // hidden 1 KB
writeResource(readerWriter, "/myFile1.meh", Buffer.alloc(1024)), // KB
writeResource(readerWriter, "/myFile2.js", Buffer.alloc(1024 * 1024)), // MB
writeResource(readerWriter, "/myFile3.properties", Buffer.alloc(1024 * 1024 * 1024)), // GB
writeResource(readerWriter, "/.myFile4", Buffer.alloc(1024)), // hidden 1 KB
]).then(() => {
const middleware = serveIndexMiddleware({
middlewareUtil: new MiddlewareUtil(),
Expand Down

0 comments on commit 7208a26

Please sign in to comment.