Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Migrated tests in test/unit/instrumentation to use node:test #2531

Merged
merged 2 commits into from
Sep 4, 2024
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
22 changes: 22 additions & 0 deletions test/lib/agent_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const https = require('https')
const semver = require('semver')
const crypto = require('crypto')
const util = require('util')
const cp = require('child_process')

const KEYPATH = path.join(__dirname, 'test-key.key')
const CERTPATH = path.join(__dirname, 'self-signed-test-certificate.crt')
Expand Down Expand Up @@ -644,3 +645,24 @@ helper.destroyProxyAgent = function destroyProxyAgent() {
helper.getShim = function getShim(pkg) {
return pkg?.[symbols.shim]
}

/**
* Executes a file in a child_process. This is intended to be
* used when you have to test destructive behavior that would be caught
* by `node:test`
*
* @param {object} params to function
* @param {string} params.cwd working directory of script
* @param {string} params.script script name
*/
helper.execSync = function execSync({ cwd, script }) {
try {
cp.execSync(`node ./${script}`, {
stdio: 'pipe',
encoding: 'utf8',
cwd
})
} catch (err) {
throw err.stderr
}
}
37 changes: 18 additions & 19 deletions test/unit/instrumentation/aws-sdk/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
*/

'use strict'
const tap = require('tap')
const test = require('node:test')
const assert = require('node:assert')
const {
grabLastUrlSegment,
setDynamoParameters
} = require('../../../../lib/instrumentation/aws-sdk/util')
const DatastoreParameters = require('../../../../lib/shim/specs/params/datastore')

tap.test('Utility Functions', (t) => {
t.ok(grabLastUrlSegment, 'imported function successfully')
test('Utility Functions', async () => {
assert.ok(grabLastUrlSegment, 'imported function successfully')

const fixtures = [
{
Expand All @@ -34,37 +36,34 @@ tap.test('Utility Functions', (t) => {

for (const [, fixture] of fixtures.entries()) {
const result = grabLastUrlSegment(fixture.input)
t.equal(result, fixture.output, `expecting ${result} to equal ${fixture.output}`)
assert.equal(result, fixture.output, `expecting ${result} to equal ${fixture.output}`)
}
t.end()
})

tap.test('DB parameters', (t) => {
t.autoend()

t.test('default values', (t) => {
test('DB parameters', async (t) => {
await t.test('default values', (t, end) => {
const input = {}
const endpoint = {}
const result = setDynamoParameters(endpoint, input)
t.same(
assert.deepEqual(
result,
{
new DatastoreParameters({
host: undefined,
database_name: null,
port_path_or_id: 443,
collection: 'Unknown'
},
}),
'should set default values for parameters'
)
t.end()
end()
})

// v2 uses host key
t.test('host, port, collection', (t) => {
await t.test('host, port, collection', (t, end) => {
const input = { TableName: 'unit-test' }
const endpoint = { host: 'unit-test-host', port: '123' }
const result = setDynamoParameters(endpoint, input)
t.same(
assert.deepEqual(
result,
{
host: endpoint.host,
Expand All @@ -74,15 +73,15 @@ tap.test('DB parameters', (t) => {
},
'should set appropriate parameters'
)
t.end()
end()
})

// v3 uses hostname key
t.test('hostname, port, collection', (t) => {
await t.test('hostname, port, collection', (t, end) => {
const input = { TableName: 'unit-test' }
const endpoint = { hostname: 'unit-test-host', port: '123' }
const result = setDynamoParameters(endpoint, input)
t.same(
assert.deepEqual(
result,
{
host: endpoint.hostname,
Expand All @@ -92,6 +91,6 @@ tap.test('DB parameters', (t) => {
},
'should set appropriate parameters'
)
t.end()
end()
})
})
Loading
Loading