Skip to content

Commit

Permalink
pkg: add qunit tests for modify() "" vs null
Browse files Browse the repository at this point in the history
Add some extra tests to make sure that `null` returned from a modify()
callback will result in a deleted file whereas "" will result in an
empty file.
  • Loading branch information
allisonkarlitskaya authored and martinpitt committed Aug 20, 2024
1 parent 79623a0 commit 5e866fc
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/base1/test-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,28 @@ QUnit.test("modify", async assert => {
assert.equal(n, 1, "callback called once");

assert.equal(await cockpit.spawn(["cat", dir + "/quux"]), "dcba\n", "correct content");

// make sure that writing "" results in an empty file, not a deleted one
n = 0;
await file.modify(old => {
n += 1;
assert.equal(old, "dcba\n", "correct old content");
return "";
});
assert.equal(n, 1, "callback called once");

assert.equal(await cockpit.spawn(["cat", dir + "/quux"]), "", "correct content");

// make sure that writing null deletes the file
n = 0;
await file.modify(old => {
n += 1;
assert.equal(old, "", "correct old content");
return null;
});
assert.equal(n, 1, "callback called once");

assert.rejects(cockpit.spawn(["cat", dir + "/quux"]), /No such file or directory/, "file deleted");
});

QUnit.test("modify with conflict", async assert => {
Expand Down

0 comments on commit 5e866fc

Please sign in to comment.