Skip to content
Closed
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
43 changes: 42 additions & 1 deletion packages/pglite-tools/tests/pg_dump.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import { pgDump } from '../dist/pg_dump.js'

describe('pgDump', () => {
it('should dump an empty database', async () => {
const pg = await PGlite.create()
const pg = await PGlite.create({
database: 'template1',
debug: undefined,
defaultDataTransferContainer: 'file',
relaxedDurability: false,
username: 'postgres',
})
const dump = await pgDump({ pg })

expect(dump).toBeInstanceOf(File)
Expand Down Expand Up @@ -61,6 +67,41 @@ describe('pgDump', () => {
expect(content).toContain('42')
})

it('specify datadir: should dump a database with tables and data', async () => {
const pg = await PGlite.create({
// dataDir: 'idb://benchmark-rd',
dataDir: '/tmp/my_data_dir',
})

// Create test tables and insert data
await pg.exec(`
CREATE TABLE test1 (
id SERIAL PRIMARY KEY,
name TEXT
);
INSERT INTO test1 (name) VALUES ('test1-row1');

CREATE TABLE test2 (
id SERIAL PRIMARY KEY,
value INTEGER
);
INSERT INTO test2 (value) VALUES (42);
`)

const dump = await pgDump({ pg })
const content = await dump.text()

// Check for table creation
expect(content).toContain('CREATE TABLE public.test1')
expect(content).toContain('CREATE TABLE public.test2')

// Check for data inserts
expect(content).toContain('INSERT INTO public.test1')
expect(content).toContain("'test1-row1'")
expect(content).toContain('INSERT INTO public.test2')
expect(content).toContain('42')
})

it('should respect custom filename', async () => {
const pg = await PGlite.create()
const dump = await pgDump({ pg, fileName: 'custom.sql' })
Expand Down
Loading