From 2c46361f611c5af766885e8197f7be0d1f967e1f Mon Sep 17 00:00:00 2001 From: Juri Leino Date: Mon, 20 Sep 2021 23:08:48 +0200 Subject: [PATCH] fix(test): test readOptionsFromEnv --- spec/envoptions.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 spec/envoptions.js diff --git a/spec/envoptions.js b/spec/envoptions.js new file mode 100644 index 0000000..cd93366 --- /dev/null +++ b/spec/envoptions.js @@ -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() +})