Skip to content

Commit cb19bfc

Browse files
committed
Sensible coverage
1 parent ca82df9 commit cb19bfc

File tree

4 files changed

+41
-35
lines changed

4 files changed

+41
-35
lines changed

lib/backend.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ function Backend({
5151
secret : null
5252
}
5353

54-
return backend
55-
5654
/* c8 ignore next 3 */
5755
function ParseComplete() {
5856
onparse()
@@ -69,6 +67,7 @@ function Backend({
6967
}
7068

7169
function NotificationResponse(x) {
70+
/* c8 ignore next 2 */
7271
if (!onnotify)
7372
return
7473

@@ -81,6 +80,7 @@ function Backend({
8180
}
8281

8382
function CommandComplete(x) {
83+
/* c8 ignore next 2 */
8484
if (!backend.query)
8585
return
8686

@@ -166,7 +166,9 @@ function Backend({
166166
const type = x.readInt32BE(5)
167167
try {
168168
type !== 0 && onauth(type, x)
169-
} catch (err) {
169+
}
170+
/* c8 ignore next 3 */
171+
catch (err) {
170172
error(err)
171173
}
172174
}
@@ -229,6 +231,9 @@ function Backend({
229231
function ReadyForQuery() {
230232
onready(backend.error)
231233
}
234+
235+
/* c8 ignore next */
236+
return backend
232237
}
233238

234239
function parseError(x) {

lib/bytes.js

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ const b = {
6767
const out = buffer.slice(0, b.i)
6868
b.i = 0
6969
buffer = Buffer.allocUnsafe(size)
70+
/* c8 ignore next */
7071
return out
7172
}
7273
}

lib/connection.js

+19-17
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ function Connection(options = {}) {
5151
error
5252
})
5353

54-
return connection
55-
5654
function onparse() {
5755
if (backend.query && backend.query.statement.sig)
5856
statements[backend.query.statement.sig] = backend.query.statement
@@ -185,19 +183,6 @@ function postgresSocket(options, {
185183
let socket
186184
let closed = true
187185

188-
return {
189-
ready: false,
190-
write: x => socket.write(x),
191-
destroy: () => {
192-
socket.destroy()
193-
return Promise.resolve()
194-
},
195-
end: () => {
196-
return new Promise(r => socket && socket.end(r))
197-
},
198-
connect
199-
}
200-
201186
function onclose() {
202187
socket.removeListener('data', data)
203188
socket.removeListener('error', error)
@@ -208,8 +193,8 @@ function postgresSocket(options, {
208193
}
209194

210195
function connect() {
211-
if (!closed)
212-
return
196+
/* c8 ignore next */
197+
if (!closed) return
213198

214199
closed = false
215200

@@ -228,6 +213,7 @@ function postgresSocket(options, {
228213
socket.removeListener('close', onclose)
229214
x.toString() === 'S'
230215
? attach(tls.connect(Object.assign({ socket }, options.ssl)))
216+
/* c8 ignore next */
231217
: error('Server does not support SSL')
232218
})
233219
}
@@ -240,4 +226,20 @@ function postgresSocket(options, {
240226
socket.once('secureConnect', ready)
241227
socket.once('close', onclose)
242228
}
229+
230+
const x = {
231+
ready: false,
232+
write: x => socket.write(x),
233+
destroy: () => {
234+
socket.destroy()
235+
return Promise.resolve()
236+
},
237+
end: () => {
238+
return new Promise(r => socket && socket.end(r))
239+
},
240+
connect
241+
}
242+
243+
/* c8 ignore next */
244+
return x
243245
}

lib/frontend.js

+13-15
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,14 @@ function connect({ user, database, connection }) {
5858
}
5959

6060
function auth(type, x, options) {
61-
return (auths[type] || authNotImplemented)(type, x, options) || ''
61+
if (type in auths)
62+
return auths[type](type, x, options)
63+
/* c8 ignore next 5 */
64+
throw errors.generic({
65+
message: 'Auth type ' + (authNames[type] || type) + ' not implemented',
66+
type: authNames[type] || type,
67+
code: 'AUTH_TYPE_NOT_IMPLEMENTED'
68+
})
6269
}
6370

6471
function AuthenticationCleartextPassword(type, x, { pass }) {
@@ -115,21 +122,12 @@ function SASLContinue(type, x, options) {
115122
}
116123

117124
function SASLFinal(type, x, options) {
118-
if (x.utf8Slice(9).split(N, 1)[0].slice(2) !== options.serverSignature) {
119-
/* c8 ignore next 5 */
120-
throw errors.generic({
121-
message: 'The server did not return the correct signature',
122-
code: 'SASL_SIGNATURE_MISMATCH'
123-
})
124-
}
125-
}
126-
127-
/* c8 ignore next 7 */
128-
function authNotImplemented(type) {
125+
if (x.utf8Slice(9).split(N, 1)[0].slice(2) === options.serverSignature)
126+
return ''
127+
/* c8 ignore next 4 */
129128
throw errors.generic({
130-
message: 'Auth type ' + (authNames[type] || type) + ' not implemented',
131-
type: authNames[type] || type,
132-
code: 'AUTH_TYPE_NOT_IMPLEMENTED'
129+
message: 'The server did not return the correct signature',
130+
code: 'SASL_SIGNATURE_MISMATCH'
133131
})
134132
}
135133

0 commit comments

Comments
 (0)