Skip to content

Commit

Permalink
Remove test globals (#3264)
Browse files Browse the repository at this point in the history
* Remove assert from globals

* Remove Client from globals

* Remove global test function

* Remove MemoryStream from globals

* Require assert in SASL integration tests

* Attempt to use a postgres with ssl?

* Use latest image

* Remove connection tests - they test internals that are better covered by testint the client
  • Loading branch information
brianc authored Jun 19, 2024
1 parent f7e484e commit 50c06f9
Show file tree
Hide file tree
Showing 81 changed files with 174 additions and 917 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
needs: lint
services:
postgres:
image: postgres:11
image: ghcr.io/railwayapp-templates/postgres-ssl
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
Expand Down
1 change: 1 addition & 0 deletions packages/pg/test/integration/client/api-tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'
var helper = require('../test-helper')
var pg = helper.pg
const assert = require('assert')

var suite = new helper.Suite()

Expand Down
1 change: 1 addition & 0 deletions packages/pg/test/integration/client/appname-tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'
var helper = require('./test-helper')
var Client = helper.Client
const assert = require('assert')

var suite = new helper.Suite()

Expand Down
1 change: 1 addition & 0 deletions packages/pg/test/integration/client/array-tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'
var helper = require('./test-helper')
var pg = helper.pg
const assert = require('assert')

var suite = new helper.Suite()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'
var helper = require('./test-helper')
var Query = helper.pg.Query
const assert = require('assert')

const suite = new helper.Suite()

Expand Down
2 changes: 2 additions & 0 deletions packages/pg/test/integration/client/configuration-tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict'
var helper = require('./test-helper')
var pg = helper.pg
const assert = require('assert')
const { Client } = helper

var suite = new helper.Suite()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const net = require('net')
const buffers = require('../../test-buffers')
const helper = require('./test-helper')
const assert = require('assert')

const suite = new helper.Suite()

Expand Down
1 change: 1 addition & 0 deletions packages/pg/test/integration/client/custom-types-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const helper = require('./test-helper')
const Client = helper.pg.Client
const suite = new helper.Suite()
const assert = require('assert')

const customTypes = {
getTypeParser: () => () => 'okay!',
Expand Down
1 change: 1 addition & 0 deletions packages/pg/test/integration/client/empty-query-tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'
var helper = require('./test-helper')
const suite = new helper.Suite()
const assert = require('assert')

suite.test('empty query message handling', function (done) {
const client = helper.client()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var helper = require('./test-helper')

var pg = helper.pg
const assert = require('assert')
const Client = pg.Client
const DatabaseError = pg.DatabaseError

Expand Down
1 change: 1 addition & 0 deletions packages/pg/test/integration/client/huge-numeric-tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'
var helper = require('./test-helper')
const pool = new helper.pg.Pool()
const assert = require('assert')

pool.connect(
assert.success(function (client, done) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'
var helper = require('./test-helper')
var Client = helper.Client
const assert = require('assert')

var suite = new helper.Suite()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
var buffers = require('../../test-buffers')
var helper = require('./test-helper')
var suite = new helper.Suite()
const assert = require('assert')

var net = require('net')

Expand Down
1 change: 1 addition & 0 deletions packages/pg/test/integration/client/no-data-tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'
var helper = require('./test-helper')
const suite = new helper.Suite()
const assert = require('assert')

suite.test('noData message handling', function () {
var client = helper.client()
Expand Down
1 change: 1 addition & 0 deletions packages/pg/test/integration/client/no-row-result-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var helper = require('./test-helper')
var pg = helper.pg
const suite = new helper.Suite()
const pool = new pg.Pool()
const assert = require('assert')

suite.test('can access results when no rows are returned', function (done) {
var checkResult = function (result) {
Expand Down
1 change: 1 addition & 0 deletions packages/pg/test/integration/client/parse-int-8-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var helper = require('../test-helper')
var pg = helper.pg
const suite = new helper.Suite()
const assert = require('assert')

const pool = new pg.Pool(helper.config)
suite.test('ability to turn on and off parser', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
var helper = require('./test-helper')
var Query = helper.pg.Query

const assert = require('assert')
var suite = new helper.Suite()

;(function () {
Expand Down
1 change: 1 addition & 0 deletions packages/pg/test/integration/client/promise-api-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const helper = require('./test-helper')
const pg = helper.pg
const assert = require('assert')

const suite = new helper.Suite()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
var bluebird = require('bluebird')
var helper = require('../test-helper')
var pg = helper.pg
const assert = require('assert')

process.on('unhandledRejection', function (e) {
console.error(e, e.stack)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'
var helper = require('../test-helper')
var pg = helper.pg
const assert = require('assert')

new helper.Suite().test('support for complex column names', function () {
const pool = new pg.Pool()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict'
var helper = require('./test-helper')
var Query = helper.pg.Query
const { Client } = helper
const assert = require('assert')

var suite = new helper.Suite()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
var helper = require('./test-helper')
var Query = helper.pg.Query
var DatabaseError = helper.pg.DatabaseError
const assert = require('assert')
const { Client } = helper
const suite = new helper.Suite()

test('error during query execution', function () {
suite.test('error during query execution', function () {
var client = new Client(helper.args)
client.connect(
assert.success(function () {
Expand Down Expand Up @@ -60,7 +63,7 @@ if (helper.config.native) {
return
}

test('9.3 column error fields', function () {
suite.test('9.3 column error fields', function () {
var client = new Client(helper.args)
client.connect(
assert.success(function () {
Expand Down Expand Up @@ -89,7 +92,7 @@ test('9.3 column error fields', function () {
)
})

test('9.3 constraint error fields', function () {
suite.test('9.3 constraint error fields', function () {
var client = new Client(helper.args)
client.connect(
assert.success(function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'
var helper = require('./test-helper')
var pg = helper.pg
const assert = require('assert')

const pool = new pg.Pool()
new helper.Suite().test('should return insert metadata', function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
'use strict'
var util = require('util')
var helper = require('./test-helper')
const assert = require('assert')
const suite = new helper.Suite()

var Client = helper.Client

var conInfo = helper.config

test('returns results as array', function () {
suite.test('returns results as array', function () {
var client = new Client(conInfo)
var checkRow = function (row) {
assert(util.isArray(row), 'row should be an array')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'
var helper = require('./test-helper')
const assert = require('assert')
const suite = new helper.Suite()

var Client = helper.Client

Expand All @@ -17,7 +19,7 @@ var checkResult = function (result) {
assert.equal(fields[2].dataTypeID, 25)
}

test('row descriptions on result object', function () {
suite.test('row descriptions on result object', function () {
var client = new Client(conInfo)
client.connect(
assert.success(function () {
Expand All @@ -33,7 +35,7 @@ test('row descriptions on result object', function () {
)
})

test('row description on no rows', function () {
suite.test('row description on no rows', function () {
var client = new Client(conInfo)
client.connect(
assert.success(function () {
Expand Down
1 change: 1 addition & 0 deletions packages/pg/test/integration/client/sasl-scram-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const helper = require('./../test-helper')
const pg = helper.pg
const suite = new helper.Suite()
const { native } = helper.args
const assert = require('assert')

/**
* This test only executes if the env variables SCRAM_TEST_PGUSER and
Expand Down
3 changes: 3 additions & 0 deletions packages/pg/test/integration/client/simple-query-tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
'use strict'
var helper = require('./test-helper')
var Query = helper.pg.Query
const assert = require('assert')
const suite = new helper.Suite()
const test = suite.test.bind(suite)

// before running this test make sure you run the script create-test-tables
test('simple query interface', function () {
Expand Down
25 changes: 14 additions & 11 deletions packages/pg/test/integration/client/ssl-tests.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
'use strict'
var pg = require('../../../lib')
var config = require('./test-helper').config
test('can connect with ssl', function () {
return false
config.ssl = {
rejectUnauthorized: false,
const helper = require('./test-helper')
const assert = require('assert')
const suite = new helper.Suite()

suite.test('can connect with ssl', function () {
const config = {
...helper.config,
ssl: {
rejectUnauthorized: false,
},
}
pg.connect(
config,
assert.success(function (client) {
return false
const client = new helper.pg.Client(config)
client.connect(
assert.success(function () {
client.query(
'SELECT NOW()',
assert.success(function () {
pg.end()
client.end()
})
)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
var helper = require('./test-helper')
var Client = helper.Client

const assert = require('assert')
var suite = new helper.Suite()

var conInfo = helper.config
Expand Down
1 change: 1 addition & 0 deletions packages/pg/test/integration/client/timezone-tests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'
var helper = require('./../test-helper')
const assert = require('assert')

var oldTz = process.env.TZ
process.env.TZ = 'Europe/Berlin'
Expand Down
1 change: 1 addition & 0 deletions packages/pg/test/integration/client/transaction-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
var helper = require('./test-helper')
const suite = new helper.Suite()
const pg = helper.pg
const assert = require('assert')

const client = new pg.Client()
client.connect(
Expand Down
1 change: 1 addition & 0 deletions packages/pg/test/integration/client/type-coercion-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
var helper = require('./test-helper')
var pg = helper.pg
const suite = new helper.Suite()
const assert = require('assert')

var testForTypeCoercion = function (type) {
const pool = new pg.Pool()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'
var helper = require('./test-helper')
const assert = require('assert')

function testTypeParser(client, expectedResult, done) {
var boolValue = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const assert = require('assert')
const suite = new helper.Suite()

const testPoolSize = function (max) {
suite.testAsync(`test ${max} queries executed on a pool rapidly`, () => {
suite.testAsync(`test ${max} queries executed on a pool rapidly`, async () => {
const pool = new helper.pg.Pool({ max: 10 })

let count = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
var helper = require('./test-helper')
const pg = helper.pg
const native = helper.args.native
const assert = require('assert')

const suite = new helper.Suite()
suite.test('connecting to invalid port', (cb) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'
var helper = require('./test-helper')
const assert = require('assert')

new helper.Suite().test('idle timeout', function () {
const config = Object.assign({}, helper.config, { idleTimeoutMillis: 50 })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
var helper = require('./../test-helper')
var pg = helper.pg
var native = helper.args.native
const assert = require('assert')

var pool = new pg.Pool()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'
var helper = require('./test-helper')
var co = require('co')
const assert = require('assert')

const pool = new helper.pg.Pool()
new helper.Suite().test(
Expand Down
Loading

0 comments on commit 50c06f9

Please sign in to comment.