Skip to content

Commit

Permalink
test: adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
metcoder95 committed Jul 19, 2024
1 parent 9750724 commit 50230f2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 58 deletions.
19 changes: 6 additions & 13 deletions test/node-test/client-dispatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ test('basic dispatch get', async (t) => {
},
onHeaders (statusCode, headers) {
p.strictEqual(statusCode, 200)
p.strictEqual(Array.isArray(headers), true)
p.ok(Object.keys(headers).length > 0)
},
onData (buf) {
bufs.push(buf)
},
onComplete (trailers) {
p.deepStrictEqual(trailers, [])
p.deepStrictEqual(trailers, {})
p.strictEqual('hello', Buffer.concat(bufs).toString('utf8'))
},
onError () {
Expand All @@ -145,7 +145,7 @@ test('basic dispatch get', async (t) => {
})

test('trailers dispatch get', async (t) => {
const p = tspl(t, { plan: 12 })
const p = tspl(t, { plan: 11 })

const server = http.createServer((req, res) => {
p.strictEqual('/', req.url)
Expand Down Expand Up @@ -180,21 +180,14 @@ test('trailers dispatch get', async (t) => {
},
onHeaders (statusCode, headers) {
p.strictEqual(statusCode, 200)
p.strictEqual(Array.isArray(headers), true)
{
const contentTypeIdx = headers.findIndex(x => x.toString() === 'Content-Type')
p.strictEqual(headers[contentTypeIdx + 1].toString(), 'text/plain')
}
p.ok(Object.keys(headers).length > 0)
p.strictEqual(headers['content-type'], 'text/plain')
},
onData (buf) {
bufs.push(buf)
},
onComplete (trailers) {
p.strictEqual(Array.isArray(trailers), true)
{
const contentMD5Idx = trailers.findIndex(x => x.toString() === 'Content-MD5')
p.strictEqual(trailers[contentMD5Idx + 1].toString(), 'test')
}
p.strictEqual(trailers['content-md5'], 'test')
p.strictEqual('hello', Buffer.concat(bufs).toString('utf8'))
},
onError () {
Expand Down
24 changes: 9 additions & 15 deletions test/node-test/diagnostics-channel/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,14 @@ test('Diagnostics channel - get', (t) => {
diagnosticsChannel.channel('undici:request:headers').subscribe(({ request, response }) => {
assert.equal(_req, request)
assert.equal(response.statusCode, 200)
const expectedHeaders = [
Buffer.from('Content-Type'),
Buffer.from('text/plain'),
Buffer.from('trailer'),
Buffer.from('foo'),
Buffer.from('Date'),
response.headers[5], // This is a date
Buffer.from('Connection'),
Buffer.from('keep-alive'),
Buffer.from('Keep-Alive'),
Buffer.from('timeout=5'),
Buffer.from('Transfer-Encoding'),
Buffer.from('chunked')
]
const expectedHeaders = {
'content-type': 'text/plain',
trailer: 'foo',
date: response.headers.date, // This is a date
connection: 'keep-alive',
'keep-alive': 'timeout=5',
'transfer-encoding': 'chunked'
}
assert.deepStrictEqual(response.headers, expectedHeaders)
assert.equal(response.statusText, 'OK')
})
Expand All @@ -114,7 +108,7 @@ test('Diagnostics channel - get', (t) => {
// This event is emitted after the last chunk has been added to the body stream,
// not when it was consumed by the application
assert.equal(endEmitted, false)
assert.deepStrictEqual(trailers, [Buffer.from('foo'), Buffer.from('oof')])
assert.deepStrictEqual(trailers, { foo: 'oof' })
resolve()
})

Expand Down
24 changes: 9 additions & 15 deletions test/node-test/diagnostics-channel/post-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,14 @@ test('Diagnostics channel - post stream', (t) => {
diagnosticsChannel.channel('undici:request:headers').subscribe(({ request, response }) => {
assert.equal(_req, request)
assert.equal(response.statusCode, 200)
const expectedHeaders = [
Buffer.from('Content-Type'),
Buffer.from('text/plain'),
Buffer.from('trailer'),
Buffer.from('foo'),
Buffer.from('Date'),
response.headers[5], // This is a date
Buffer.from('Connection'),
Buffer.from('keep-alive'),
Buffer.from('Keep-Alive'),
Buffer.from('timeout=5'),
Buffer.from('Transfer-Encoding'),
Buffer.from('chunked')
]
const expectedHeaders = {
'content-type': 'text/plain',
trailer: 'foo',
date: response.headers.date, // This is a date
connection: 'keep-alive',
'keep-alive': 'timeout=5',
'transfer-encoding': 'chunked'
}
assert.deepStrictEqual(response.headers, expectedHeaders)
assert.equal(response.statusText, 'OK')
})
Expand All @@ -120,7 +114,7 @@ test('Diagnostics channel - post stream', (t) => {
// This event is emitted after the last chunk has been added to the body stream,
// not when it was consumed by the application
assert.equal(endEmitted, false)
assert.deepStrictEqual(trailers, [Buffer.from('foo'), Buffer.from('oof')])
assert.deepStrictEqual(trailers, { foo: 'oof' })
resolve()
})

Expand Down
24 changes: 9 additions & 15 deletions test/node-test/diagnostics-channel/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,14 @@ test('Diagnostics channel - post', (t) => {
diagnosticsChannel.channel('undici:request:headers').subscribe(({ request, response }) => {
assert.equal(_req, request)
assert.equal(response.statusCode, 200)
const expectedHeaders = [
Buffer.from('Content-Type'),
Buffer.from('text/plain'),
Buffer.from('trailer'),
Buffer.from('foo'),
Buffer.from('Date'),
response.headers[5], // This is a date
Buffer.from('Connection'),
Buffer.from('keep-alive'),
Buffer.from('Keep-Alive'),
Buffer.from('timeout=5'),
Buffer.from('Transfer-Encoding'),
Buffer.from('chunked')
]
const expectedHeaders = {
'content-type': 'text/plain',
trailer: 'foo',
date: response.headers.date, // This is a date
connection: 'keep-alive',
'keep-alive': 'timeout=5',
'transfer-encoding': 'chunked'
}
assert.deepStrictEqual(response.headers, expectedHeaders)
assert.equal(response.statusText, 'OK')
})
Expand All @@ -118,7 +112,7 @@ test('Diagnostics channel - post', (t) => {
// This event is emitted after the last chunk has been added to the body stream,
// not when it was consumed by the application
assert.equal(endEmitted, false)
assert.deepStrictEqual(trailers, [Buffer.from('foo'), Buffer.from('oof')])
assert.deepStrictEqual(trailers, { foo: 'oof' })
resolve()
})

Expand Down

0 comments on commit 50230f2

Please sign in to comment.