Skip to content
This repository has been archived by the owner on Nov 5, 2018. It is now read-only.

Commit

Permalink
[nock] att/get
Browse files Browse the repository at this point in the history
first binary test runnin
  • Loading branch information
dscape committed Dec 2, 2011
1 parent 6910cb0 commit 613acfb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
, "Artur Konarski (http://tarantoga.com)"
, "Pedro Teixeira <pedro.teixeira@gmail.com> (http://metaduck.com)"
]
, "keywords" : ["couchdb", "data", "request", "json", "nosql", "micro", "nano"]
, "keywords" : ["couchdb", "data", "request", "json", "nosql", "micro", "nano", "database"]
, "dependencies" : {"request": "2.2.0", "underscore": "~1.1.7"}
, "devDependencies" : { "async": "~0.1.9", "ensure": "0.4.6", "nock": "0.5.x"}
, "scripts" : { "test": "./node_modules/ensure/bin/tap.js tests/*/*.js" }
Expand Down
38 changes: 37 additions & 1 deletion tests/att/get.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,48 @@
var ensure = require('ensure')
, nock = require('nock')
, cfg = require('../../cfg/tests.js')
, nano = require('../../nano')(cfg)
, db_name = require('../utils').db_name("att_ge")
, tests = exports
, pixel = "Qk06AAAAAAAAADYAAAAoAAAAAQAAAP////8BABgAAAAAAAAAAAATCwAAEwsAAAAAAAAAAAAAWm2CAA=="
, couch
;

couch = nock(cfg.url)
.put('/' + db_name('a'))
.reply(201, "{\"ok\":true}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
location: cfg.url + '/' + db_name('a'),
date: 'Fri, 02 Dec 2011 16:34:28 GMT',
'content-type': 'application/json',
'content-length': '12',
'cache-control': 'must-revalidate' })
.put('/' + db_name('a') + '/new/att', '"Hello"')
.reply(201, "{\"ok\":true,\"id\":\"new\",\"rev\":\"1-5142a2e74e1ec33e6e5b621418210283\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
location: cfg.url + '/' + db_name('a') + '/new/att',
etag: '"1-5142a2e74e1ec33e6e5b621418210283"',
date: 'Fri, 02 Dec 2011 16:34:29 GMT',
'content-type': 'text/plain;charset=utf-8',
'content-length': '66',
'cache-control': 'must-revalidate' })
.put('/' + db_name('a') + '/new/att?rev=1-5142a2e74e1ec33e6e5b621418210283'
, new Buffer(pixel, 'base64').toString())
.reply(201, "{\"ok\":true,\"id\":\"new\",\"rev\":\"2-3b1f88c637fde74a486cf3ce5558b47e\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
location: cfg.url + '/' + db_name('a') + '/new/att',
etag: '"2-3b1f88c637fde74a486cf3ce5558b47e"',
date: 'Fri, 02 Dec 2011 16:34:29 GMT',
'content-type': 'text/plain;charset=utf-8',
'content-length': '66',
'cache-control': 'must-revalidate' })
.get('/' + db_name('a') + '/new/att?rev=2-3b1f88c637fde74a486cf3ce5558b47e')
.reply(200, new Buffer(pixel, 'base64'), { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
etag: '"2-3b1f88c637fde74a486cf3ce5558b47e"',
date: 'Fri, 02 Dec 2011 16:34:30 GMT',
'content-type': 'image/bmp',
'content-md5': 'Ow9j2dR0Qm58Qi3z8p2w3A==',
'content-length': '58',
'cache-control': 'must-revalidate',
'accept-ranges': 'bytes' });

function db(i) { return nano.use(db_name(i)); }

tests.att_get = function (callback) {
Expand All @@ -24,7 +61,6 @@ tests.att_get = function (callback) {
};

tests.att_get_ok = function (e,b) {
nano.db.destroy(db_name('a'));
this.t.notOk(e, 'No Error');
var from_buffer = new Buffer(b, "binary").toString("base64");
this.t.equal(from_buffer, pixel, 'Buffer is pixel');
Expand Down

0 comments on commit 613acfb

Please sign in to comment.