Skip to content

Commit

Permalink
test: Migrated root smoke tests to node:test (#2771)
Browse files Browse the repository at this point in the history
  • Loading branch information
bizob2828 authored Nov 20, 2024
1 parent ff2d8d0 commit 78f2709
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 183 deletions.
77 changes: 0 additions & 77 deletions test/smoke/client-s3.tap.js

This file was deleted.

66 changes: 66 additions & 0 deletions test/smoke/client-s3.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2023 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

'use strict'
const test = require('node:test')
const assert = require('node:assert')
const helper = require('../lib/agent_helper')
const {
DESTINATIONS: { TRANS_SEGMENT }
} = require('../../lib/config/attribute-filter')

test('@aws-sdk/client-s3 functionality', async (t) => {
const { version, name } = require('@aws-sdk/client-s3/package')
// eslint-disable-next-line no-console
console.log(`AWS package: ${name} version: ${version}`)
const agent = helper.instrumentMockedAgent()
const { S3, ...lib } = require('@aws-sdk/client-s3')
const client = new S3({ region: 'us-east-2' })
const { GetObjectCommand } = lib

t.after(() => {
helper.unloadAgent(agent)
})

await helper.runInTransaction(agent, async (transaction) => {
const command = new GetObjectCommand({
Bucket: 'node-agent-aws-smoke-tests',
Key: 'test-file.json'
})

const { Body } = await client.send(command)
const fileContents = JSON.parse(await Body.transformToString())

assert.deepEqual(
fileContents,
{ items: [{ name: 'Item 1' }, { name: 'Item 2' }] },
'should successfully fetch test-file.json from S3'
)

transaction.end()

const { url, procedure, ...awsAttributes } =
transaction.trace.root.children[1].attributes.get(TRANS_SEGMENT)

delete awsAttributes.nr_exclusive_duration_millis

assert.equal(
url,
'http://node-agent-aws-smoke-tests.s3.us-east-2.amazonaws.com/test-file.json',
'should have url attribute in segment'
)
assert.equal(procedure, 'GET', 'should have method attribute in segment')
assert.deepEqual(
awsAttributes,
{
'aws.operation': 'GetObjectCommand',
'aws.requestId': 'Unknown',
'aws.service': 'S3',
'aws.region': 'us-east-2'
},
'should have the proper AWS attributes in segment'
)
})
})
32 changes: 16 additions & 16 deletions test/smoke/lasp_connect.tap.js → test/smoke/lasp-connect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
*/

'use strict'

const tap = require('tap')
const test = require('node:test')
const assert = require('node:assert')
const configurator = require('../../lib/config')
const Agent = require('../../lib/agent')
const CollectorAPI = require('../../lib/collector/api')
const { getTestSecret } = require('../helpers/secrets')
const laspLicense = getTestSecret('LASP_LICENSE')
const laspSecureLicense = getTestSecret('LASP_SECURE_LICENSE')

tap.test('connecting with a LASP token should not error', (t) => {
test('connecting with a LASP token should not error', (t, end) => {
const config = configurator.initialize({
app_name: 'node.js Tests',
license_key: laspLicense,
Expand All @@ -34,22 +34,22 @@ tap.test('connecting with a LASP token should not error', (t) => {
const api = new CollectorAPI(agent)

api.connect(function (error, response) {
t.notOk(error, 'connected without error')
assert.ok(!error, 'connected without error')

const returned = response && response.payload
t.ok(returned, 'got boot configuration')
t.ok(returned.agent_run_id, 'got run ID')
t.ok(agent.config.run_id, 'run ID set in configuration')
assert.ok(returned, 'got boot configuration')
assert.ok(returned.agent_run_id, 'got run ID')
assert.ok(agent.config.run_id, 'run ID set in configuration')

api.shutdown(function (error) {
t.notOk(error, 'should have shut down without issue')
t.notOk(agent.config.run_id, 'run ID should have been cleared by shutdown')
t.end()
assert.ok(!error, 'should have shut down without issue')
assert.ok(!agent.config.run_id, 'run ID should have been cleared by shutdown')
end()
})
})
})

tap.test('missing required policies should result in shutdown', (t) => {
test('missing required policies should result in shutdown', (t, end) => {
const config = configurator.initialize({
app_name: 'node.js Tests',
license_key: laspSecureLicense,
Expand All @@ -69,10 +69,10 @@ tap.test('missing required policies should result in shutdown', (t) => {
const agent = new Agent(config)

agent.start(function (error, response) {
t.ok(error, 'should have error')
t.equal(error.message, 'Failed to connect to collector')
t.notOk(response, 'should not have response payload')
t.equal(agent._state, 'errored')
t.end()
assert.ok(error, 'should have error')
assert.equal(error.message, 'Failed to connect to collector')
assert.ok(!response, 'should not have response payload')
assert.equal(agent._state, 'errored')
end()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@
*/

'use strict'

const test = require('node:test')
const net = require('net')
const tap = require('tap')
const configurator = require('../../lib/config')
const Agent = require('../../lib/agent')
const CollectorAPI = require('../../lib/collector/api')
const { getTestSecret } = require('../helpers/secrets')
const license = getTestSecret('TEST_LICENSE')
const { tspl } = require('@matteo.collina/tspl')

tap.test('proxy authentication should set headers', (t) => {
t.plan(2)
test('proxy authentication should set headers', async (t) => {
const plan = tspl(t, { plan: 2 })

const server = net.createServer()

server.on('connection', (socket) => {
socket.on('data', (chunk) => {
const data = chunk.toString().split('\r\n')
t.equal(data[0], 'CONNECT staging-collector.newrelic.com:443 HTTP/1.1')
t.equal(data[1], 'Proxy-Authorization: Basic YTpi')
plan.equal(data[0], 'CONNECT staging-collector.newrelic.com:443 HTTP/1.1')
plan.equal(data[1], 'Proxy-Authorization: Basic YTpi')
server.close()
})
socket.end()
Expand Down Expand Up @@ -52,7 +52,10 @@ tap.test('proxy authentication should set headers', (t) => {
const api = new CollectorAPI(agent)

api.connect(() => {
t.end()
// need a callback even though we dont care and
// are just asserting some of the outgoing http requests above
})
})

await plan.completed
})
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
*/

'use strict'

const tap = require('tap')
const test = require('node:test')
const assert = require('node:assert')
const configurator = require('../../lib/config')
const Agent = require('../../lib/agent')
const CollectorAPI = require('../../lib/collector/api')
const { getTestSecret } = require('../helpers/secrets')

const license = getTestSecret('TEST_LICENSE')
tap.test('no proxy set should not use proxy agent', (t) => {
test('no proxy set should not use proxy agent', (t, end) => {
const config = configurator.initialize({
app_name: 'node.js Tests',
license_key: license,
Expand All @@ -34,18 +34,17 @@ tap.test('no proxy set should not use proxy agent', (t) => {
const api = new CollectorAPI(agent)

api.connect((error, response) => {
t.notOk(error, 'connected without error')
assert.ok(!error, 'connected without error')

const returned = response && response.payload
t.ok(returned, 'got boot configuration')
t.ok(returned.agent_run_id, 'got run ID')
t.ok(agent.config.run_id, 'run ID set in configuration')
assert.ok(returned, 'got boot configuration')
assert.ok(returned.agent_run_id, 'got run ID')
assert.ok(agent.config.run_id, 'run ID set in configuration')

api.shutdown((error) => {
t.notOk(error, 'should have shut down without issue')
t.notOk(agent.config.run_id, 'run ID should have been cleared by shutdown')

t.end()
assert.ok(!error, 'should have shut down without issue')
assert.ok(!agent.config.run_id, 'run ID should have been cleared by shutdown')
end()
})
})
})
72 changes: 0 additions & 72 deletions test/smoke/s3-presigned-url.tap.js

This file was deleted.

Loading

0 comments on commit 78f2709

Please sign in to comment.