-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwriters.test.ts
More file actions
66 lines (58 loc) · 2.58 KB
/
Copy pathwriters.test.ts
File metadata and controls
66 lines (58 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { mkdtempSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
import { LocalContentStore } from "@openislands/storage";
import { createInMemoryDuckDB, resolveWriter } from "../src/writers.js";
function tempDir(): string {
const dir = mkdtempSync(join(tmpdir(), "oi-writers-"));
mkdirSync(join(dir, "data"), { recursive: true });
return dir;
}
describe("appendLines EOL preservation", () => {
it("preserves CRLF when appending a row to a CRLF CSV", async () => {
const dir = tempDir();
const csvPath = "data/meals.csv";
// Seed a CSV whose every line ending is CRLF
writeFileSync(join(dir, csvPath), "name,kcal\r\nOatmeal,300\r\n");
const store = new LocalContentStore(dir);
const writer = resolveWriter(store, { dataset: "meals", source: csvPath });
await writer.insert([{ name: "Eggs", kcal: 200 }]);
const content = readFileSync(join(dir, csvPath), "utf8");
// The new row must be present
expect(content).toContain("Eggs");
// After stripping every \r\n there must be no lone \n left
expect(content.split("\r\n").join("")).not.toContain("\n");
});
it("preserves LF when appending a row to an LF CSV", async () => {
const dir = tempDir();
const csvPath = "data/meals.csv";
writeFileSync(join(dir, csvPath), "name,kcal\nOatmeal,300\n");
const store = new LocalContentStore(dir);
const writer = resolveWriter(store, { dataset: "meals", source: csvPath });
await writer.insert([{ name: "Eggs", kcal: 200 }]);
const content = readFileSync(join(dir, csvPath), "utf8");
expect(content).toContain("Eggs");
// No \r must be introduced
expect(content).not.toContain("\r");
});
});
describe("createInMemoryDuckDB resource bounds", () => {
// Guards the container OOM fix: an unbounded thread count over a cgroup-capped memory_limit
// fails to pin buffers at boot, and a default temp_directory spills to a non-writable cwd.
it("caps threads and sets a writable temp_directory", async () => {
const instance = await createInMemoryDuckDB();
const conn = await instance.connect();
try {
const reader = await conn.runAndReadAll(
"SELECT current_setting('threads') AS threads, current_setting('temp_directory') AS temp_directory",
);
const [row] = reader.getRowObjects();
expect(Number(row.threads)).toBe(4);
expect(String(row.temp_directory)).toContain("openislands-duckdb");
} finally {
conn.closeSync();
instance.closeSync();
}
});
});