Skip to content

Commit

Permalink
test against fixed expected
Browse files Browse the repository at this point in the history
  • Loading branch information
bmacnaughton committed Jan 21, 2025
1 parent 58a6a47 commit c61d8b9
Show file tree
Hide file tree
Showing 6 changed files with 2,734 additions and 34 deletions.
81 changes: 47 additions & 34 deletions lib/log-processor/log-processor.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import assert from 'node:assert';
import fsp from 'node:fs/promises';
import os from 'node:os';

import expected from '../../test/log-files/expected.mjs';

let desc = describe;
if (os.type() === 'os-you-want-to-skip') {
desc = describe.skip;
Expand All @@ -18,40 +20,44 @@ desc('log-processor - stdout', function() {
for (const file of files) {
let results;

it(`${file}: read/process with default reporter`, async function() {
it(`${file}: read/process with default reporter (csv)`, async function() {
results = cp.spawnSync('node', ['lib/log-processor/index.mjs', `./test/log-files/${file}`]);

const stdout = results.stdout.toString();
assert.equal(stdout, expected.csv.stdout[file], 'stdout does not match');
assert.strictEqual(results.status, 0);
});

it(`${file}: read/process specifying csv reporter`, async function() {
const previous = results.stdout.toString();

const env = Object.assign({}, process.env, {CSI_RM_REPORTER: 'csv'});
results = cp.spawnSync('node', ['lib/log-processor/index.mjs', `./test/log-files/${file}`], {env});

assert.strictEqual(results.status, 0);
assert.strictEqual(results.stdout.toString(), previous);
const stdout = results.stdout.toString();
assert.strictEqual(stdout, expected.csv.stdout[file], 'stdout does not match');
});

it(`${file}: csv & csv-deprecated are the same`, async function() {
it(`${file}: csv-deprecated output is the same`, async function() {
const previous = results.stdout.toString();

const env = Object.assign({}, process.env, {CSI_RM_REPORTER: 'csv2'});
const env = Object.assign({}, process.env, {CSI_RM_REPORTER: 'csv-deprecated'});
results = cp.spawnSync('node', ['lib/log-processor/index.mjs', `./test/log-files/${file}`], {env});

assert.strictEqual(results.status, 0);
assert.strictEqual(results.stdout.toString(), previous);
const stdout = results.stdout.toString();
assert.strictEqual(stdout, previous, 'stdout does not match');
});

it(`${file}: read/process with json reporter`, async function() {
const env = Object.assign({}, process.env, {CSI_RM_REPORTER: 'json'});
results = cp.spawnSync('node', ['lib/log-processor/index.mjs', `./test/log-files/${file}`], {env});

assert.strictEqual(results.status, 0);
const stdout = results.stdout.toString();
assert.strictEqual(stdout, expected.json.stdout[file], 'stdout does not match');
});

it(`${file}: json & json-deprecated are the same`, async function() {
it(`${file}: json-deprecated output is the same`, async function() {
const previous = results.stdout.toString();
const env = Object.assign({}, process.env, {CSI_RM_REPORTER: 'json-deprecated'});
results = cp.spawnSync('node', ['lib/log-processor/index.mjs', `./test/log-files/${file}`], {env});
Expand All @@ -71,72 +77,79 @@ desc('log-processor - file', function() {
];

for (const file of files) {
let results;
let expected;

it(`${file}: read/process with default reporter`, async function() {
const env = Object.assign({}, process.env, {CSI_RM_OUTPUT: 'output-1'});
results = cp.spawnSync('node', ['lib/log-processor/index.mjs', `./test/log-files/${file}`], {env});
const results = cp.spawnSync('node', ['lib/log-processor/index.mjs', `./test/log-files/${file}`], {env});

assert.notStrictEqual(results, null);
assert.ok(!results.error);
assert.strictEqual(results.status, 0);
expected = await fsp.readFile('output-1', 'utf8');

const stdout = results.stdout.toString();
assert.strictEqual(stdout, expected.csv.fileStdout[file], 'stdout does not match');

const written = await fsp.readFile('output-1', 'utf8');
assert.equal(written, expected.csv.file[file], 'files do not match');
});

it(`${file}: read/process specifying csv reporter`, async function() {
const previous = results.stdout.toString();

const env = Object.assign({}, process.env, {CSI_RM_REPORTER: 'csv', CSI_RM_OUTPUT: 'output-2'});
results = cp.spawnSync('node', ['lib/log-processor/index.mjs', `./test/log-files/${file}`], {env});
const results = cp.spawnSync('node', ['lib/log-processor/index.mjs', `./test/log-files/${file}`], {env});

assert.notStrictEqual(results, null);
assert.ok(!results.error);
assert.strictEqual(results.status, 0);
assert.strictEqual(results.stdout.toString(), previous, 'stdout does not match');

const contents = await fsp.readFile('output-2', 'utf8');
assert.strictEqual(contents, expected, 'files do not match');
});
const stdout = results.stdout.toString();
assert.strictEqual(stdout, expected.csv.fileStdout[file], 'stdout does not match');

it(`${file}: csv & csv-deprecated are the same`, async function() {
const previous = results.stdout.toString();
const written = await fsp.readFile('output-2', 'utf8');
assert.strictEqual(written, expected.csv.file[file], 'files do not match');
});

it(`${file}: csv-deprecated writes the same output`, async function() {
const env = Object.assign({}, process.env, {CSI_RM_REPORTER: 'csv-deprecated', CSI_RM_OUTPUT: 'output-2'});
results = cp.spawnSync('node', ['lib/log-processor/index.mjs', `./test/log-files/${file}`], {env});
const results = cp.spawnSync('node', ['lib/log-processor/index.mjs', `./test/log-files/${file}`], {env});

assert.notStrictEqual(results, null);
assert.ok(!results.error);
assert.strictEqual(results.status, 0);
assert.strictEqual(results.stdout.toString(), previous, 'stdout does not match');

const contents = await fsp.readFile('output-2', 'utf8');
assert.strictEqual(contents, expected, 'files do not match');
const stdout = results.stdout.toString();
assert.strictEqual(stdout, expected.csv.fileStdout[file], 'stdout does not match');

const written = await fsp.readFile('output-2', 'utf8');
assert.strictEqual(written, expected.csv.file[file], 'files do not match');
});

it(`${file}: read/process with json reporter`, async function() {
const env = Object.assign({}, process.env, {CSI_RM_REPORTER: 'json', CSI_RM_OUTPUT: 'output-1'});
results = cp.spawnSync('node', ['lib/log-processor/index.mjs', `./test/log-files/${file}`], {env});
const results = cp.spawnSync('node', ['lib/log-processor/index.mjs', `./test/log-files/${file}`], {env});

assert.notStrictEqual(results, null);
assert.ok(!results.error);
assert.strictEqual(results.status, 0);

expected = await fsp.readFile('output-1', 'utf8');
const stdout = results.stdout.toString();
assert.strictEqual(stdout, '', 'stdout does not match');

const written = await fsp.readFile('output-1', 'utf8');
assert.equal(written, expected.json.file[file], 'files do not match');
});

it(`${file}: json & json-deprecated are the same`, async function() {
const previous = results.stdout.toString();
it(`${file}: json-deprecated writes the same output`, async function() {
const env = Object.assign({}, process.env, {CSI_RM_REPORTER: 'json-deprecated', CSI_RM_OUTPUT: 'output-2'});
results = cp.spawnSync('node', ['lib/log-processor/index.mjs', `./test/log-files/${file}`], {env});
const results = cp.spawnSync('node', ['lib/log-processor/index.mjs', `./test/log-files/${file}`], {env});

assert.notStrictEqual(results, null);
assert.ok(!results.error);
assert.strictEqual(results.status, 0);
assert.strictEqual(results.stdout.toString(), previous, 'stdout does not match');

const contents = await fsp.readFile('output-2', 'utf8');
assert.strictEqual(contents, expected, 'files do not match');
const stdout = results.stdout.toString();
assert.strictEqual(stdout, '', 'stdout does not match');

const written = await fsp.readFile('output-2', 'utf8');
assert.strictEqual(written, expected.json.file[file], 'files do not match');
});
}
});
5 changes: 5 additions & 0 deletions test/log-files/expected-minimal.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
route, status, n, mean, stddev, percentiles: 0.5, 0.7, 0.8, 0.9, 0.95
GET https://localhost:40419/info,200,1,4.00,0.00,4,4,4,4,4
POST https://localhost:40419/echo,200,1,13.00,0.00,13,13,13,13,13
POST https://localhost:40419/meta,200,1,5.00,0.00,5,5,5,5,5

Loading

0 comments on commit c61d8b9

Please sign in to comment.