Skip to content

Commit

Permalink
chore: Migrate block of unit tests to node:test
Browse files Browse the repository at this point in the history
  • Loading branch information
jsumners-nr committed Sep 13, 2024
1 parent 2f7a5f0 commit 311593a
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 311593a

Please sign in to comment.