Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions packages/gaussdb-cursor/test/close.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const assert = require('assert')
const Cursor = require('../')
const pg = require('gaussdb')
const gaussdb = require('gaussdb')

const text = 'SELECT generate_series as num FROM generate_series(0, 50)'
describe('close', function () {
beforeEach(function (done) {
const client = (this.client = new pg.Client())
const client = (this.client = new gaussdb.Client())
client.connect(done)
})

Expand Down
12 changes: 6 additions & 6 deletions packages/gaussdb-cursor/test/error-handling.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict'
const assert = require('assert')
const Cursor = require('../')
const pg = require('gaussdb')
const gaussdb = require('gaussdb')

const text = 'SELECT generate_series as num FROM generate_series(0, 4)'

describe('error handling', function () {
it('can continue after error', function (done) {
const client = new pg.Client()
const client = new gaussdb.Client()
client.connect()
const cursor = client.query(new Cursor('asdfdffsdf'))
cursor.read(1, function (err) {
Expand All @@ -21,7 +21,7 @@ describe('error handling', function () {
})

it('errors queued reads', async () => {
const client = new pg.Client()
const client = new gaussdb.Client()
await client.connect()

const cursor = client.query(new Cursor('asdfdffsdf'))
Expand Down Expand Up @@ -55,7 +55,7 @@ describe('error handling', function () {

describe('read callback does not fire sync', () => {
it('does not fire error callback sync', (done) => {
const client = new pg.Client()
const client = new gaussdb.Client()
client.connect()
const cursor = client.query(new Cursor('asdfdffsdf'))
let after = false
Expand All @@ -75,7 +75,7 @@ describe('read callback does not fire sync', () => {
})

it('does not fire result sync after finished', (done) => {
const client = new pg.Client()
const client = new gaussdb.Client()
client.connect()
const cursor = client.query(new Cursor('SELECT NOW()'))
let after = false
Expand All @@ -100,7 +100,7 @@ describe('read callback does not fire sync', () => {

describe('proper cleanup', function () {
it('can issue multiple cursors on one client', function (done) {
const client = new pg.Client()
const client = new gaussdb.Client()
client.connect()
const cursor1 = client.query(new Cursor(text))
cursor1.read(8, function (err, rows) {
Expand Down
34 changes: 17 additions & 17 deletions packages/gaussdb-cursor/test/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const assert = require('assert')
const Cursor = require('../')
const pg = require('gaussdb')
const gaussdb = require('gaussdb')

const text = 'SELECT generate_series as num FROM generate_series(0, 5)'

describe('cursor', function () {
beforeEach(function (done) {
const client = (this.client = new pg.Client())
const client = (this.client = new gaussdb.Client())
client.connect(done)

this.pgCursor = function (text, values) {
this.gaussdbCursor = function (text, values) {
return client.query(new Cursor(text, values || []))
}
})
Expand All @@ -19,7 +19,7 @@ describe('cursor', function () {
})

it('fetch 6 when asking for 10', function (done) {
const cursor = this.pgCursor(text)
const cursor = this.gaussdbCursor(text)
cursor.read(10, function (err, res) {
assert.ifError(err)
assert.strictEqual(res.length, 6)
Expand All @@ -28,7 +28,7 @@ describe('cursor', function () {
})

it('end before reading to end', function (done) {
const cursor = this.pgCursor(text)
const cursor = this.gaussdbCursor(text)
cursor.read(3, function (err, res) {
assert.ifError(err)
assert.strictEqual(res.length, 3)
Expand All @@ -37,15 +37,15 @@ describe('cursor', function () {
})

it('callback with error', function (done) {
const cursor = this.pgCursor('select asdfasdf')
const cursor = this.gaussdbCursor('select asdfasdf')
cursor.read(1, function (err) {
assert(err)
done()
})
})

it('read a partial chunk of data', function (done) {
const cursor = this.pgCursor(text)
const cursor = this.gaussdbCursor(text)
cursor.read(2, function (err, res) {
assert.ifError(err)
assert.strictEqual(res.length, 2)
Expand All @@ -67,7 +67,7 @@ describe('cursor', function () {
})

it('read return length 0 past the end', function (done) {
const cursor = this.pgCursor(text)
const cursor = this.gaussdbCursor(text)
cursor.read(2, function (err) {
assert(!err)
cursor.read(100, function (err, res) {
Expand All @@ -86,7 +86,7 @@ describe('cursor', function () {
this.timeout(10000)
const text = 'SELECT generate_series as num FROM generate_series(0, 100000)'
const values = []
const cursor = this.pgCursor(text, values)
const cursor = this.gaussdbCursor(text, values)
let count = 0
const read = function () {
cursor.read(100, function (err, rows) {
Expand All @@ -108,7 +108,7 @@ describe('cursor', function () {
it('normalizes parameter values', function (done) {
const text = 'SELECT $1::json me'
const values = [{ name: 'brian' }]
const cursor = this.pgCursor(text, values)
const cursor = this.gaussdbCursor(text, values)
cursor.read(1, function (err, rows) {
if (err) return done(err)
assert.strictEqual(rows[0].me.name, 'brian')
Expand All @@ -121,7 +121,7 @@ describe('cursor', function () {
})

it('returns result along with rows', function (done) {
const cursor = this.pgCursor(text)
const cursor = this.gaussdbCursor(text)
cursor.read(1, function (err, rows, result) {
assert.ifError(err)
assert.strictEqual(rows.length, 1)
Expand All @@ -135,7 +135,7 @@ describe('cursor', function () {
})

it('emits row events', function (done) {
const cursor = this.pgCursor(text)
const cursor = this.gaussdbCursor(text)
cursor.read(10)
cursor.on('row', (row, result) => result.addRow(row))
cursor.on('end', (result) => {
Expand All @@ -145,7 +145,7 @@ describe('cursor', function () {
})

it('emits row events when cursor is closed manually', function (done) {
const cursor = this.pgCursor(text)
const cursor = this.gaussdbCursor(text)
cursor.on('row', (row, result) => result.addRow(row))
cursor.on('end', (result) => {
assert.strictEqual(result.rows.length, 3)
Expand All @@ -156,19 +156,19 @@ describe('cursor', function () {
})

it('emits error events', function (done) {
const cursor = this.pgCursor('select asdfasdf')
const cursor = this.gaussdbCursor('select asdfasdf')
cursor.on('error', function (err) {
assert(err)
done()
})
})

it('returns rowCount on insert', function (done) {
const pgCursor = this.pgCursor
const gaussdbCursor = this.gaussdbCursor
this.client
.query('CREATE TEMPORARY TABLE pg_cursor_test (foo VARCHAR(1), bar VARCHAR(1))')
.query('CREATE TEMPORARY TABLE gaussdb_cursor_test (foo VARCHAR(1), bar VARCHAR(1))')
.then(function () {
const cursor = pgCursor('insert into pg_cursor_test values($1, $2)', ['a', 'b'])
const cursor = gaussdbCursor('insert into gaussdb_cursor_test values($1, $2)', ['a', 'b'])
cursor.read(1, function (err, rows, result) {
assert.ifError(err)
assert.strictEqual(rows.length, 0)
Expand Down
4 changes: 2 additions & 2 deletions packages/gaussdb-cursor/test/no-data-handling.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const assert = require('assert')
const pg = require('gaussdb')
const gaussdb = require('gaussdb')
const Cursor = require('../')

describe('queries with no data', function () {
beforeEach(function (done) {
const client = (this.client = new pg.Client())
const client = (this.client = new gaussdb.Client())
client.connect(done)
})

Expand Down
6 changes: 3 additions & 3 deletions packages/gaussdb-cursor/test/pool.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'
const assert = require('assert')
const Cursor = require('../')
const pg = require('gaussdb')
const gaussdb = require('gaussdb')

const text = 'SELECT generate_series as num FROM generate_series(0, 50)'

Expand Down Expand Up @@ -33,7 +33,7 @@ function poolQueryPromise(pool, readRowCount) {

describe('pool', function () {
beforeEach(function () {
this.pool = new pg.Pool({ max: 1 })
this.pool = new gaussdb.Pool({ max: 1 })
})

afterEach(function () {
Expand Down Expand Up @@ -85,7 +85,7 @@ describe('pool', function () {
})

it('can close multiple times on a pool', async function () {
const pool = new pg.Pool({ max: 1 })
const pool = new gaussdb.Pool({ max: 1 })
const run = async () => {
const cursor = new Cursor(text)
const client = await pool.connect()
Expand Down
12 changes: 6 additions & 6 deletions packages/gaussdb-cursor/test/promises.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const assert = require('assert')
const Cursor = require('../')
const pg = require('gaussdb')
const gaussdb = require('gaussdb')

const text = 'SELECT generate_series as num FROM generate_series(0, 5)'

describe('cursor using promises', function () {
beforeEach(function (done) {
const client = (this.client = new pg.Client())
const client = (this.client = new gaussdb.Client())
client.connect(done)

this.pgCursor = function (text, values) {
this.gaussdbCursor = function (text, values) {
return client.query(new Cursor(text, values || []))
}
})
Expand All @@ -19,21 +19,21 @@ describe('cursor using promises', function () {
})

it('resolve with result', async function () {
const cursor = this.pgCursor(text)
const cursor = this.gaussdbCursor(text)
const res = await cursor.read(6)
assert.strictEqual(res.length, 6)
})

it('reject with error', function (done) {
const cursor = this.pgCursor('select asdfasdf')
const cursor = this.gaussdbCursor('select asdfasdf')
cursor.read(1).catch((err) => {
assert(err)
done()
})
})

it('read multiple times', async function () {
const cursor = this.pgCursor(text)
const cursor = this.gaussdbCursor(text)
let res

res = await cursor.read(2)
Expand Down
6 changes: 3 additions & 3 deletions packages/gaussdb-cursor/test/query-config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict'
const assert = require('assert')
const Cursor = require('../')
const pg = require('gaussdb')
const gaussdb = require('gaussdb')

describe('query config passed to result', () => {
it('passes rowMode to result', (done) => {
const client = new pg.Client()
const client = new gaussdb.Client()
client.connect()
const text = 'SELECT generate_series as num FROM generate_series(0, 5)'
const cursor = client.query(new Cursor(text, null, { rowMode: 'array' }))
Expand All @@ -18,7 +18,7 @@ describe('query config passed to result', () => {
})

it('passes types to result', (done) => {
const client = new pg.Client()
const client = new gaussdb.Client()
client.connect()
const text = 'SELECT generate_series as num FROM generate_series(0, 2)'
const types = {
Expand Down
8 changes: 4 additions & 4 deletions packages/gaussdb-cursor/test/transactions.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const assert = require('assert')
const Cursor = require('../')
const pg = require('gaussdb')
const gaussdb = require('gaussdb')

// SKIP: 不支持 LISTEN/NOFITY statement
// https://github.com/HuaweiCloudDeveloper/gaussdb-drivers/blob/master-dev/diff-gaussdb-postgres.md#%E4%B8%8D%E6%94%AF%E6%8C%81-listennofity-statement
describe.skip('transactions', () => {
it('can execute multiple statements in a transaction', async () => {
const client = new pg.Client()
const client = new gaussdb.Client()
await client.connect()
await client.query('begin')
await client.query('CREATE TEMP TABLE foobar(id SERIAL PRIMARY KEY)')
Expand All @@ -20,7 +20,7 @@ describe.skip('transactions', () => {
})

it('can execute multiple statements in a transaction if ending cursor early', async () => {
const client = new pg.Client()
const client = new gaussdb.Client()
await client.connect()
await client.query('begin')
await client.query('CREATE TEMP TABLE foobar(id SERIAL PRIMARY KEY)')
Expand All @@ -31,7 +31,7 @@ describe.skip('transactions', () => {
})

it('can execute multiple statements in a transaction if no data', async () => {
const client = new pg.Client()
const client = new gaussdb.Client()
await client.connect()
await client.query('begin')
// create a cursor that has no data response
Expand Down
4 changes: 2 additions & 2 deletions packages/gaussdb-esm-test/common-js-imports.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ for (const path of paths) {

describe('pg-native', () => {
it('should work with commonjs', async () => {
const pg = require('gaussdb')
const gaussdb = require('gaussdb')

const pool = new pg.native.Pool()
const pool = new gaussdb.native.Pool()
const result = await pool.query('SELECT 1')
assert.strictEqual(result.rowCount, 1)
pool.end()
Expand Down
6 changes: 3 additions & 3 deletions packages/gaussdb-esm-test/gaussdb.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from 'node:assert'
import { describe, it } from 'node:test'
import pg, {
import gaussdb, {
Client,
Pool,
Connection,
Expand All @@ -13,7 +13,7 @@ import pg, {
TypeOverrides,
} from 'gaussdb'

describe('pg', () => {
describe('gaussdb', () => {
it('should export Client constructor', () => {
assert.ok(new Client())
})
Expand All @@ -23,7 +23,7 @@ describe('pg', () => {
})

it('should still provide default export', () => {
assert.ok(new pg.Pool())
assert.ok(new gaussdb.Pool())
})

it('should export Connection constructor', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/gaussdb-protocol/src/inbound-parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ const parseBuffers = async (buffers: Buffer[]): Promise<BackendMessage[]> => {
return msgs
}

describe('PgPacketStream', function () {
describe('GaussDBPacketStream', function () {
testForMessage(authOkBuffer, expectedAuthenticationOkayMessage)
testForMessage(plainPasswordBuffer, expectedPlainPasswordMessage)
testForMessage(md5PasswordBuffer, expectedMD5PasswordMessage)
Expand Down
2 changes: 1 addition & 1 deletion packages/gaussdb-query-stream/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class QueryStream extends Readable implements Submittable {
this.handleError = this.cursor.handleError.bind(this.cursor)
this.handleEmptyQuery = this.cursor.handleEmptyQuery.bind(this.cursor)

// pg client sets types via _result property
// gaussdb client sets types via _result property
this._result = this.cursor._result
}

Expand Down
Loading