Skip to content

Commit

Permalink
update zlib tests to account for platform differences
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydaly committed Mar 25, 2021
1 parent 23343af commit 2fa8b6a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ jobs:

strategy:
matrix:
node-version: [10.x, 12.x, 14.x, 15.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
node-version: [14.x]

steps:
- uses: actions/checkout@v2
Expand Down
4 changes: 2 additions & 2 deletions __tests__/errorHandling.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ describe('Error Handling Tests:', function() {
console.log = log => { try { _log = JSON.parse(log) } catch(e) { _log = log } }
let result = await new Promise(r => api9.run(_event,{},(e,res) => { r(res) }))
console.log = logger
// console.log(result);
expect(result).toEqual({ multiValueHeaders: { 'content-encoding': ['gzip'], 'content-type': ['application/json'] }, statusCode: 500, body: 'H4sIAAAAAAAAE6tWSi0qyi9SslIKycgsVgCiRIWS1OIShZKMovzyPAWIrI5SfHJpcUl+rpJVSVFpKpCblFicamYC4dYCAL2BVyJFAAAA', isBase64Encoded: true })
let body = gzipSync(`{"error":"This is a test thrown error","_custom":true,"_base64":true}`).toString('base64')
expect(result).toEqual({ multiValueHeaders: { 'content-encoding': ['gzip'], 'content-type': ['application/json'] }, statusCode: 500, body, isBase64Encoded: true })
})
})
}) // end ERROR HANDLING tests
30 changes: 24 additions & 6 deletions __tests__/responses.unit.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict';


const sinon = require('sinon') // Require Sinon.js library
const AWS = require('aws-sdk') // AWS SDK (automatically available in Lambda)
const S3 = require('../lib/s3-service') // Init S3 Service
const { gzipSync } = require('zlib')
const { gzipSync, brotliCompressSync, deflateSync } = require('zlib')

// Init API instance
const api = require('../index')({ version: 'v1.0' })
Expand Down Expand Up @@ -129,7 +128,7 @@ api4.get('/testGZIP', function(req,res) {
res.json({ object: true })
})

api5.get('/testGZIP', function(req,res) {
api5.get('/testCompression', function(req,res) {
res.json({ object: true })
})

Expand Down Expand Up @@ -285,13 +284,32 @@ describe('Response Tests:', function() {
it('Custom serializer (GZIP)', async function() {
let _event = Object.assign({},event,{ path: '/testGZIP'})
let result = await new Promise(r => api4.run(_event,{},(e,res) => { r(res) }))
expect(result).toEqual({ multiValueHeaders: { 'content-encoding': ['gzip'], 'content-type': ['application/json'] }, statusCode: 200, body: 'H4sIAAAAAAAAE6tWyk/KSk0uUbIqKSpN1VGKTy4tLsnPhXOTEotTzUwg3FoAan86iy0AAAA=', isBase64Encoded: true })

let body = gzipSync(`{"object":true,"_custom":true,"_base64":true}`).toString('base64')
expect(result).toEqual({ multiValueHeaders: { 'content-encoding': ['gzip'], 'content-type': ['application/json'] }, statusCode: 200, body, isBase64Encoded: true })
}) // end it

it('Compression (GZIP)', async function() {
let _event = Object.assign({},event,{ path: '/testGZIP'})
let _event = Object.assign({},event,{ path: '/testCompression'})
let result = await new Promise(r => api5.run(_event,{},(e,res) => { r(res) }))
let body = gzipSync(`{"object":true}`).toString('base64')
expect(result).toEqual({ multiValueHeaders: { 'content-encoding': ['gzip'], 'content-type': ['application/json'] }, statusCode: 200, body, isBase64Encoded: true })
}) // end it

it('Compression (Brotli)', async function() {
let _event = Object.assign({},event,{ path: '/testCompression'})
_event.multiValueHeaders['Accept-Encoding'] = ['br','deflate','gzip']
let result = await new Promise(r => api5.run(_event,{},(e,res) => { r(res) }))
let body = brotliCompressSync(`{"object":true}`).toString('base64')
expect(result).toEqual({ multiValueHeaders: { 'content-encoding': ['br'], 'content-type': ['application/json'] }, statusCode: 200, body, isBase64Encoded: true })
}) // end it

it('Compression (Deflate)', async function() {
let _event = Object.assign({},event,{ path: '/testCompression'})
_event.multiValueHeaders['Accept-Encoding'] = ['deflate']
let result = await new Promise(r => api5.run(_event,{},(e,res) => { r(res) }))
expect(result).toEqual({ multiValueHeaders: { 'content-encoding': ['gzip'], 'content-type': ['application/json'] }, statusCode: 200, body: 'H4sIAAAAAAAAE6tWyk/KSk0uUbIqKSpNrQUAAQd5Ug8AAAA=', isBase64Encoded: true })
let body = deflateSync(`{"object":true}`).toString('base64')
expect(result).toEqual({ multiValueHeaders: { 'content-encoding': ['deflate'], 'content-type': ['application/json'] }, statusCode: 200, body, isBase64Encoded: true })
}) // end it

afterEach(function() {
Expand Down

0 comments on commit 2fa8b6a

Please sign in to comment.