mirror of
https://git.proxmox.com/git/package-rebuilds
synced 2025-08-22 14:27:59 +00:00
98 lines
2.4 KiB
JavaScript
98 lines
2.4 KiB
JavaScript
'use strict'
|
|
|
|
const { test } = require('tap')
|
|
const { Client, Pool } = require('..')
|
|
const http = require('http')
|
|
const https = require('https')
|
|
const pem = require('https-pem')
|
|
const fs = require('fs')
|
|
|
|
if (process.platform !== 'win32') {
|
|
test('http unix get', (t) => {
|
|
t.plan(7)
|
|
|
|
const server = http.createServer((req, res) => {
|
|
t.equal('/', req.url)
|
|
t.equal('GET', req.method)
|
|
t.equal('localhost', req.headers.host)
|
|
res.setHeader('Content-Type', 'text/plain')
|
|
res.end('hello')
|
|
})
|
|
t.teardown(server.close.bind(server))
|
|
|
|
try {
|
|
fs.unlinkSync('/var/tmp/test3.sock')
|
|
} catch (err) {
|
|
|
|
}
|
|
|
|
server.listen('/var/tmp/test3.sock', () => {
|
|
const client = new Client({
|
|
hostname: 'localhost',
|
|
protocol: 'http:'
|
|
}, {
|
|
socketPath: '/var/tmp/test3.sock'
|
|
})
|
|
t.teardown(client.close.bind(client))
|
|
|
|
client.request({ path: '/', method: 'GET' }, (err, data) => {
|
|
t.error(err)
|
|
const { statusCode, headers, body } = data
|
|
t.equal(statusCode, 200)
|
|
t.equal(headers['content-type'], 'text/plain')
|
|
const bufs = []
|
|
body.on('data', (buf) => {
|
|
bufs.push(buf)
|
|
})
|
|
body.on('end', () => {
|
|
t.equal('hello', Buffer.concat(bufs).toString('utf8'))
|
|
})
|
|
})
|
|
})
|
|
})
|
|
|
|
test('http unix get pool', (t) => {
|
|
t.plan(7)
|
|
|
|
const server = http.createServer((req, res) => {
|
|
t.equal('/', req.url)
|
|
t.equal('GET', req.method)
|
|
t.equal('localhost', req.headers.host)
|
|
res.setHeader('Content-Type', 'text/plain')
|
|
res.end('hello')
|
|
})
|
|
t.teardown(server.close.bind(server))
|
|
|
|
try {
|
|
fs.unlinkSync('/var/tmp/test3.sock')
|
|
} catch (err) {
|
|
|
|
}
|
|
|
|
server.listen('/var/tmp/test3.sock', () => {
|
|
const client = new Pool({
|
|
hostname: 'localhost',
|
|
protocol: 'http:'
|
|
}, {
|
|
socketPath: '/var/tmp/test3.sock'
|
|
})
|
|
t.teardown(client.close.bind(client))
|
|
|
|
client.request({ path: '/', method: 'GET' }, (err, data) => {
|
|
t.error(err)
|
|
const { statusCode, headers, body } = data
|
|
t.equal(statusCode, 200)
|
|
t.equal(headers['content-type'], 'text/plain')
|
|
const bufs = []
|
|
body.on('data', (buf) => {
|
|
bufs.push(buf)
|
|
})
|
|
body.on('end', () => {
|
|
t.equal('hello', Buffer.concat(bufs).toString('utf8'))
|
|
})
|
|
})
|
|
})
|
|
})
|
|
|
|
}
|