Skip to content

Commit

Permalink
fix(test): test readOptionsFromEnv
Browse files Browse the repository at this point in the history
  • Loading branch information
line-o committed Sep 20, 2021
1 parent f2189a7 commit 2c46361
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions spec/envoptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const test = require('tape')
const { readOptionsFromEnv } = require('../index')

test('read connection options from environment', function (t) {
t.equal(typeof readOptionsFromEnv, 'function')
t.end()
})

test('read connection options from environment', function (t) {
const optionsFromEnv = readOptionsFromEnv()
const userIsSet = process.env.EXISTDB_USER && 'EXISTDB_PASS' in process.env
const serverIsSet = process.env.EXISTDB_SERVER

if (serverIsSet) {
const { hostname, port, protocol } = new URL(process.env.EXISTDB_SERVER)
t.equal(optionsFromEnv.port, port)
t.equal(optionsFromEnv.secure, protocol === 'https:')
t.equal(optionsFromEnv.host, hostname)
} else {
t.false('port' in optionsFromEnv)
t.false('secure' in optionsFromEnv)
t.false('host' in optionsFromEnv)
}

if (userIsSet) {
t.ok(optionsFromEnv.basic_auth)
t.equal(optionsFromEnv.basic_auth.user, process.env.EXISTDB_USER)
t.equal(optionsFromEnv.basic_auth.pass, process.env.EXISTDB_PASS)
} else {
t.false('basic_auth' in optionsFromEnv)
}

t.end()
})

0 comments on commit 2c46361

Please sign in to comment.