Skip to content

Commit

Permalink
Throw if entity is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Aug 25, 2014
1 parent e01a4b8 commit 029e90c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ var crypto = require('crypto')
*/

function etag(entity) {
if (entity == null) {
throw new TypeError('argument entity is required')
}

if (entity.length === 0) {
// fast-path empty body
return '"1B2M2Y8AsgTpgAmY7PhCfg=="'
Expand Down
4 changes: 4 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ var assert = require('assert')
var etag = require('..')

describe('etag(entity)', function () {
it('should require an entity', function () {
assert.throws(etag.bind(), /argument entity is required/)
})

describe('when "entity" is a string', function () {
it('should generate an ETag', function () {
assert.equal(etag('beep boop'), '"Z34SGyQ2IB7YzB7HMkCjrQ=="')
Expand Down

0 comments on commit 029e90c

Please sign in to comment.