Skip to content

Commit

Permalink
chore: Migrate second block of unit tests to node:test (newrelic#2572)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsumners-nr authored and sumitsuthar committed Sep 20, 2024
1 parent 5cf1fa4 commit d554848
Show file tree
Hide file tree
Showing 3 changed files with 455 additions and 477 deletions.
86 changes: 39 additions & 47 deletions test/unit/db_util.test.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,45 @@
/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* Copyright 2024 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

'use strict'
const tap = require('tap')
const util = require('../../lib/db/utils')

tap.test('DB Utilities:', function (t) {
const useParser = util.extractDatabaseChangeFromUse

t.test('should match single statement use expressions', function (t) {
t.equal(useParser('use test_db;'), 'test_db')
t.equal(useParser('USE INIT'), 'INIT')
t.end()
})

t.test('should not be sensitive to ; omission', function (t) {
t.equal(useParser('use test_db'), 'test_db')
t.end()
})

t.test('should not be sensitive to extra ;', function (t) {
t.equal(useParser('use test_db;;;;;;'), 'test_db')
t.end()
})

t.test('should not be sensitive to extra white space', function (t) {
t.equal(useParser(' use test_db;'), 'test_db')
t.equal(useParser('use test_db;'), 'test_db')
t.equal(useParser(' use test_db;'), 'test_db')
t.equal(useParser('use test_db ;'), 'test_db')
t.equal(useParser('use test_db; '), 'test_db')
t.end()
})

t.test('should match backtick expressions', function (t) {
t.equal(useParser('use `test_db`;'), '`test_db`')
t.equal(useParser('use `☃☃☃☃☃☃`;'), '`☃☃☃☃☃☃`')
t.end()
})

t.test('should not match malformed use expressions', function (t) {
t.equal(useParser('use cxvozicjvzocixjv`oasidfjaosdfij`;'), null)
t.equal(useParser('use `oasidfjaosdfij`123;'), null)
t.equal(useParser('use `oasidfjaosdfij` 123;'), null)
t.equal(useParser('use \u0001;'), null)
t.equal(useParser('use oasidfjaosdfij 123;'), null)
t.end()
})
t.end()

const test = require('node:test')
const assert = require('node:assert')

const useParser = require('../../lib/db/utils').extractDatabaseChangeFromUse

test('should match single statement use expressions', () => {
assert.equal(useParser('use test_db;'), 'test_db')
assert.equal(useParser('USE INIT'), 'INIT')
})

test('should not be sensitive to ; omission', () => {
assert.equal(useParser('use test_db'), 'test_db')
})

test('should not be sensitive to extra ;', () => {
assert.equal(useParser('use test_db;;;;;;'), 'test_db')
})

test('should not be sensitive to extra white space', () => {
assert.equal(useParser(' use test_db;'), 'test_db')
assert.equal(useParser('use test_db;'), 'test_db')
assert.equal(useParser(' use test_db;'), 'test_db')
assert.equal(useParser('use test_db ;'), 'test_db')
assert.equal(useParser('use test_db; '), 'test_db')
})

test('should match backtick expressions', () => {
assert.equal(useParser('use `test_db`;'), '`test_db`')
assert.equal(useParser('use `☃☃☃☃☃☃`;'), '`☃☃☃☃☃☃`')
})

test('should not match malformed use expressions', () => {
assert.equal(useParser('use cxvozicjvzocixjv`oasidfjaosdfij`;'), null)
assert.equal(useParser('use `oasidfjaosdfij`123;'), null)
assert.equal(useParser('use `oasidfjaosdfij` 123;'), null)
assert.equal(useParser('use \u0001;'), null)
assert.equal(useParser('use oasidfjaosdfij 123;'), null)
})
Loading

0 comments on commit d554848

Please sign in to comment.