- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
哪些测试框架可用于测试 View ,它是我的 CouchDB 的 map
和 reduce
函数、过滤器、列表、显示等?
理想情况下,该框架允许对每个函数进行单元测试,并支持针对 CouchDB 实例上的数据集测试一组给定的 View 、过滤器等。
我在 writing a test suite for the CouchDB API 上找到了一篇博文但这是从 2010 年开始的,我想知道从那以后发生了什么。
最佳答案
我会使用 Expresso Node.js 的 TDD 框架。编写 Node.js 应用程序的开销不会白费。
从下载页面安装 Node.js:nodejs.org/download
确保您还获得了 npm(node.js 包管理器)。
使用 expresso 框架,您可以轻松地测试 CouchDB 中的任何 RESTful 函数。
这是一个与 CouchDB 通信的示例 node.js 测试:
var http = require('http');
var url = require('url');
var log_level = 5;
var base_url = 'http://localhost:5984/';
var delete_db_at_end = false;
/**
* This test fetches all the data from a database and verifies that the data is
* returned as it should.
*/
exports.testCouchDBCartoonsAllDocs = function(beforeExit, assert) {
curl('GET', base_url + 'cartoons/_all_docs', null, function(response) {
assert.equal(7, response.total_rows);
assert.equal('Donald Duck', response.rows[1].id);
});
}
/**
* This test creates a database for this test only and deletes it at the end if the
* global parameter delete_db_at_end is set to true, otherwise it is left as is for
* human inspection.
*
*/
exports.testCreateDatabaseTestAddAndDestroy = function(beforeExit, assert) {
var dbname = 'test_db_cartoon';
deleteExistingDatabase(dbname, assert, function(response) {
/* Create the database */
curl('PUT', base_url + dbname, null, function(response) {
assert.equal(true, response.ok);
curl('PUT', base_url + dbname + '/Donald+Duck', '{"publisher":"Walt Disney"}', function(response){
assert.equal(true, response.ok);
assert.equal('Donald Duck', response.id);
curl('GET', base_url + dbname + '/Donald+Duck', null, function(response) {
assert.equal('Donald Duck', response._id);
assert.equal('Walt Disney', response.publisher);
/* Finally we delete the database from CouchDB */
if (delete_db_at_end) {
deleteExistingDatabase(dbname, assert, function(response) {
assert.equal(true, response.ok);
});
}
});
});
});
});
}
/**
* This is a helper function that deletes the database if it exists so
* that the tests can run even if they where interrupted.
*/
function deleteExistingDatabase(dbname, assert, callback) {
curl('GET', base_url + dbname, null, function(response) {
if (response.db_name === dbname) {
log(1, 'About to delete the database ' + dbname);
curl('DELETE', base_url + '/' + dbname, null, function(response) {
callback(response);
});
} else {
callback(response);
}
});
}
/**
* This is a helper method to manage the RESTful sending to the database
*/
function curl(method, urlString, payload, callback) {
log(1, method + ' ' + urlString);
var auth = 'Basic ' + new Buffer('username:password').toString('base64');
log(7, auth);
var options = url.parse(urlString);
options.method = method;
options.headers = {
'Content-Encoding': 'UTF8',
'Content-Type': 'application/json',
'Authorization' : auth
};
log(7, options);
var req = http.request(options, function (res) {
var data = "";
res.setEncoding('UTF8');
res.on('data', function (chunk) {
data += chunk;
});
res.on('end', function (chunk) {
var response = JSON.parse(data);
log(5, response);
callback(response);
});
});
if (payload) {
req.write(payload);
}
req.end();
}
/**
* This simple logger logs message depending on the log_level set at
* the top of this file.
*/
function log(level, message) {
if (level<=log_level) {
console.log(message);
}
}
在存储此文件的同一文件夹中执行此命令:
npm install expresso
通过发出此命令运行测试:
node_modules/expresso/bin/expresso test.js
这是上面命令的控制台输出:
GET http://localhost:5984/cartoons/_all_docs
GET http://localhost:5984/test_db_cartoon
{ error: 'not_found', reason: 'no_db_file' }
PUT http://localhost:5984/test_db_cartoon
{ total_rows: 7,
offset: 0,
rows:
[ { id: 'Batman', key: 'Batman', value: [Object] },
{ id: 'Donald Duck', key: 'Donald Duck', value: [Object] },
{ id: 'Iron Man', key: 'Iron Man', value: [Object] },
{ id: 'Mickey Mouse', key: 'Mickey Mouse', value: [Object] },
{ id: 'Spider-Man', key: 'Spider-Man', value: [Object] },
{ id: 'Superman', key: 'Superman', value: [Object] },
{ id: '_design/select', key: '_design/select', value: [Object] } ] }
{ ok: true }
PUT http://localhost:5984/test_db_cartoon/Donald+Duck
{ ok: true,
id: 'Donald Duck',
rev: '1-1c431dfb2c46991ec999743830a5363b' }
GET http://localhost:5984/test_db_cartoon/Donald+Duck
{ _id: 'Donald Duck',
_rev: '1-1c431dfb2c46991ec999743830a5363b',
publisher: 'Walt Disney' }
100% 2 tests
您可以通过额外的方式轻松扩展测试
exports.testname = function(beforeExit, assert) {
}
关于测试 CouchDB View 、过滤器、列表、显示等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11160587/
我正在设计一个用于任务管理的移动应用程序(待办事项列表以及许多额外的好东西),可以离线使用并在重新连接时同步。 Couch 和 Pouch DB 给我留下了深刻的印象,但我仍然不确定数据库和角色的最佳
CouchDB 中如何实现多范围查询?对于单个范围条件, startkey 和 endkey 组合工作正常,但同样的事情不适用于多范围条件。 我的 View 函数是这样的: "function(doc
是否可以在不同的 CouchDB 数据库之间进行连接?我知道,我可以将所有数据放入同一个数据库中,但我想使用 Ubuntus DesktopCouch,它有一些默认数据库,比如我想使用的联系人和笔记。
给定以下对象结构: { key1: "...", key2: "...", data: "..." } 有没有办法通过查询 key1 和 key2 而不设置两个不同的 View (每
我从 CouchDB 开始,需要一点帮助。 我有很多数据在表中列出给用户。用户应该能够通过多个动态参数过滤该数据。 例如。假设有一个包含日期、作者、标签、is_published、标题字段的表。 用户
刚刚在 mac 山狮上使用 brew 安装了 CouchDb。一切顺利,直到我遇到以下问题启动服务器我不知道 erlnag 并且无法分析转储文件 `couchdb Apache CouchDB 1.2
在使用关系数据库工作了这么长时间后,我真的很努力地理解这个新概念...... 谁能解释我应该如何进行存储,比如类别层次结构? 在关系数据库中,我有: 类别: 类别编号 父类别 ID 姓名 或那种性质的
我希望有人可以在这里验证或更正我的结论。 我正在考虑写一个小的副项目。我想创建一个用于记笔记的桌面应用程序,该应用程序将同步到 Web 服务器,以便多个安装可以保持同步并共享数据,并且如果需要,还可以
我试图在单个 CouchDB 文档中存储多个独立附件,并为每个附件分配任意属性(即描述)。是否有这样做的约定?据我所知,我无法将它们插入 _attachments直接构造。提前致谢! 最佳答案 您不能
关闭。这个问题是opinion-based .它目前不接受答案。 想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题. 2年前关闭。 Improve t
这些功能是什么? 我在哪里可以阅读有关它们如何工作的信息? CouchDB 权威指南没有解释它,很奇怪。 最佳答案 来自 CouchDB 权威指南: There are other design do
我一直在阅读 Linked documents在 CouchDb 文档中,它看起来很好。 但是是否可以在数据库 A 中编写一个 View 来从数据库 B 发出文档?我需要它,因为我们在不同的数据库中存
使用 CouchDB 1.0.1。 我删除了一些文件,然后我放了一些其他的文件 _id作为删除的。 现在这些新文档有 _deleted_conflicts field : "_deleted_conf
我想实现一个 webapp - 一个集成来自各种来源的数据并将它们显示给用户的提要。用户应该只能看到他有权阅读的提要项目(例如,因为它们属于他所属的项目)。但是,许多用户可能(并且将会)看到一个提要项
我是 CouchDB 的新手并正在学习它。我没有遇到 CouchDB 对参照完整性的支持。 我们可以为 CouchDB 文档中的字段创建外键吗? 例如是否可以确保供应商数据库中提供订单文档中使用的供应
是否有任何技术/建议来强制执行独特的约束?是的,我们可以创建唯一的 key ,但我们不能更改 key 和 key ,而且这种方法不适合复杂的验证(单独的唯一登录、单独的唯一电子邮件等...) 例如,一
我有一个问题,我已经尝试回答一段时间了,但无法弄清楚: 您如何设计或划分 CouchDB 文档? 以博客文章为例。 半“关系”方法是创建一些对象: 发帖 用户 评论 标签 片段 这很有道理。但我正在尝
CouchDB 可以在同一台机器上处理数千个独立的数据库吗? 假设您有一组 BankTransaction。有数千条记录。 (编辑:实际上并不存储事务——只需考虑大量非常小的、频繁更新的记录。它基本上
我有一个 CouchDB 数据库,主要存储文档附件。 文件存储在数据库中,URL 结构如下:/db-name/numeric-file-id/official-human-readable-file-
我正在阅读 Apress 的《Beginning CouchDB》一书,其中有一行让我有点困惑: Also important to note is that CouchDB will never o
我是一名优秀的程序员,十分优秀!