Skip to content
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

Test uses prefix of the current user ID and cleanup for failed tests #15

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
55 changes: 30 additions & 25 deletions test/ksds.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,36 +35,49 @@ function readUntilEnd(file, done) {
);
}

const prefix=require("os").userInfo().username;
const testDsn=prefix + ".TEST.VSAM.KSDS2";
const schema=JSON.parse(fs.readFileSync('test/test.json'));

describe("Key Sequenced Dataset", function() {
before(function() {
// Cleanup after failed tests
if (vsam.exist(testDsn)) {
var file = vsam.openSync(testDsn,
JSON.parse(fs.readFileSync('test/test.json')));
expect(file.close()).to.not.throw;
file.dealloc((err) => {
assert.ifError(err);
});
}
});

it("ensure test dataset does not exist", function(done) {
expect(vsam.exist("BARBOZA.TEST.VSAM.KSDS2")).to.be.false;
expect(vsam.exist(testDsn)).to.be.false;
done();
});

it("create an empty dataset", function(done) {
var file = vsam.allocSync("BARBOZA.TEST.VSAM.KSDS2",
JSON.parse(fs.readFileSync('test/test.json')))
var file = vsam.allocSync(testDsn, schema);
expect(file).not.be.null;
expect(file.close()).to.not.throw;
done();
});

it("ensure test dataset exists", function(done) {
expect(vsam.exist("BARBOZA.TEST.VSAM.KSDS2")).to.be.true;
expect(vsam.exist(testDsn)).to.be.true;
done();
});

it("open and close the existing dataset", function(done) {
var file = vsam.openSync("BARBOZA.TEST.VSAM.KSDS2",
JSON.parse(fs.readFileSync('test/test.json')))
var file = vsam.openSync(testDsn, schema);
expect(file).to.not.be.null;
expect(file.close()).to.not.throw;
done();
});

it("write new record", function(done) {
var file = vsam.openSync("BARBOZA.TEST.VSAM.KSDS2",
JSON.parse(fs.readFileSync('test/test.json')))
var file = vsam.openSync(testDsn, schema);
record = {
key: "00126",
name: "JOHN",
Expand All @@ -78,8 +91,7 @@ describe("Key Sequenced Dataset", function() {
});

it("read a record and verify properties", function(done) {
var file = vsam.openSync("BARBOZA.TEST.VSAM.KSDS2",
JSON.parse(fs.readFileSync('test/test.json')))
var file = vsam.openSync(testDsn, schema);
file.read( (record, err) => {
assert.ifError(err);
expect(record).to.not.be.null;
Expand All @@ -92,8 +104,7 @@ describe("Key Sequenced Dataset", function() {
});

it("find existing record and verify data", function(done) {
var file = vsam.openSync("BARBOZA.TEST.VSAM.KSDS2",
JSON.parse(fs.readFileSync('test/test.json')))
var file = vsam.openSync(testDsn, schema);
file.find("00126", (record, err) => {
assert.ifError(err);
assert.equal(record.key, "00126", "record has been created");
Expand All @@ -105,8 +116,7 @@ describe("Key Sequenced Dataset", function() {
});

it("write new record after read", function(done) {
var file = vsam.openSync("BARBOZA.TEST.VSAM.KSDS2",
JSON.parse(fs.readFileSync('test/test.json')))
var file = vsam.openSync(testDsn, schema);
file.read((record, err) => {
record.key = "00125";
record.name = "JANE";
Expand All @@ -126,8 +136,7 @@ describe("Key Sequenced Dataset", function() {
});

it("delete existing record", function(done) {
var file = vsam.openSync("BARBOZA.TEST.VSAM.KSDS2",
JSON.parse(fs.readFileSync('test/test.json')))
var file = vsam.openSync(testDsn, schema);
file.find("00126", (record, err) => {
file.delete( (err) => {
assert.ifError(err);
Expand All @@ -141,30 +150,27 @@ describe("Key Sequenced Dataset", function() {
});

it("reads all records until the end", function(done) {
var file = vsam.openSync("BARBOZA.TEST.VSAM.KSDS2",
JSON.parse(fs.readFileSync('test/test.json')))
var file = vsam.openSync(testDsn, schema);
readUntilEnd(file, done);
});

it("open a vsam file with incorrect key length", function(done) {
expect(() => {
vsam.openSync("BARBOZA.TEST.VSAM.KSDS2",
vsam.openSync(testDsn,
JSON.parse(fs.readFileSync('test/test-error.json')))
}).to.throw(/Incorrect key length/);
done();
});

it("return error for non-existent dataset", function(done) {
expect(() => {
vsam.openSync("A..B",
JSON.parse(fs.readFileSync('test/test.json')))
vsam.openSync("A..B", schema);
}).to.throw(/Invalid dataset name/);
done();
});

it("update existing record and delete it", function(done) {
var file = vsam.openSync("BARBOZA.TEST.VSAM.KSDS2",
JSON.parse(fs.readFileSync('test/test.json')))
var file = vsam.openSync(testDsn, schema);
file.find("00125", (record, err) => {
assert.ifError(err);
record.name = "KEVIN";
Expand All @@ -186,8 +192,7 @@ describe("Key Sequenced Dataset", function() {
});

it("deallocate a dataset", function(done) {
var file = vsam.openSync("BARBOZA.TEST.VSAM.KSDS2",
JSON.parse(fs.readFileSync('test/test.json')))
var file = vsam.openSync(testDsn, schema);
expect(file.close()).to.not.throw;
file.dealloc((err) => {
assert.ifError(err);
Expand Down