Reorganized test and force 100% code coverage (#1226)
This commit is contained in:
committed by
delvedor
parent
acce06c2af
commit
24961869cc
@ -20,7 +20,7 @@ const {
|
||||
} = require('./errors')
|
||||
|
||||
class Connection {
|
||||
constructor (opts = {}) {
|
||||
constructor (opts) {
|
||||
this.url = opts.url
|
||||
this.ssl = opts.ssl || null
|
||||
this.id = opts.id || stripAuth(opts.url.href)
|
||||
@ -64,6 +64,7 @@ class Connection {
|
||||
// https://github.com/nodejs/node/commit/b961d9fd83
|
||||
if (INVALID_PATH_REGEX.test(requestParams.path) === true) {
|
||||
callback(new TypeError(`ERR_UNESCAPED_CHARACTERS: ${requestParams.path}`), null)
|
||||
/* istanbul ignore next */
|
||||
return { abort: () => {} }
|
||||
}
|
||||
|
||||
@ -73,6 +74,7 @@ class Connection {
|
||||
// listen for the response event
|
||||
// TODO: handle redirects?
|
||||
request.on('response', response => {
|
||||
/* istanbul ignore else */
|
||||
if (ended === false) {
|
||||
ended = true
|
||||
this._openRequests--
|
||||
@ -87,6 +89,7 @@ class Connection {
|
||||
|
||||
// handles request timeout
|
||||
request.on('timeout', () => {
|
||||
/* istanbul ignore else */
|
||||
if (ended === false) {
|
||||
ended = true
|
||||
this._openRequests--
|
||||
@ -97,6 +100,7 @@ class Connection {
|
||||
|
||||
// handles request error
|
||||
request.on('error', err => {
|
||||
/* istanbul ignore else */
|
||||
if (ended === false) {
|
||||
ended = true
|
||||
this._openRequests--
|
||||
@ -107,6 +111,7 @@ class Connection {
|
||||
// updates the ended state
|
||||
request.on('abort', () => {
|
||||
debug('Request aborted', params)
|
||||
/* istanbul ignore else */
|
||||
if (ended === false) {
|
||||
ended = true
|
||||
this._openRequests--
|
||||
@ -121,7 +126,7 @@ class Connection {
|
||||
if (isStream(params.body) === true) {
|
||||
pump(params.body, request, err => {
|
||||
/* istanbul ignore if */
|
||||
if (err != null && ended === false) {
|
||||
if (err != null && /* istanbul ignore next */ ended === false) {
|
||||
ended = true
|
||||
this._openRequests--
|
||||
callback(err, null)
|
||||
@ -300,6 +305,7 @@ function resolve (host, path) {
|
||||
|
||||
function prepareHeaders (headers = {}, auth) {
|
||||
if (auth != null && headers.authorization == null) {
|
||||
/* istanbul ignore else */
|
||||
if (auth.apiKey) {
|
||||
if (typeof auth.apiKey === 'object') {
|
||||
headers.authorization = 'ApiKey ' + Buffer.from(`${auth.apiKey.id}:${auth.apiKey.api_key}`).toString('base64')
|
||||
|
||||
Reference in New Issue
Block a user