Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing 如何单元测试文档是否具有给定的权限?_Unit Testing_Marklogic_Marklogic 10 - Fatal编程技术网

Unit testing 如何单元测试文档是否具有给定的权限?

Unit testing 如何单元测试文档是否具有给定的权限?,unit-testing,marklogic,marklogic-10,Unit Testing,Marklogic,Marklogic 10,我正在使用marklogic单元测试设置单元测试,我想做的一件事是检查给定文档是否具有特定权限。然而,当我根据一系列权限测试我的权限时,我得到一个XDMP-NONMIXEDCOMPLEXCONT错误。我假设这与权限是复杂的对象而不是简单的字符串有关,因为这适用于集合 const test = require("/test/test-helper.xqy"); let p1 = Sequence.from([xdmp.permission("rest-reader&q

我正在使用marklogic单元测试设置单元测试,我想做的一件事是检查给定文档是否具有特定权限。然而,当我根据一系列权限测试我的权限时,我得到一个
XDMP-NONMIXEDCOMPLEXCONT
错误。我假设这与权限是复杂的对象而不是简单的字符串有关,因为这适用于集合

const test = require("/test/test-helper.xqy");
let p1 = Sequence.from([xdmp.permission("rest-reader", "read", "element")]);
let p2 = Sequence.from([
  xdmp.permission("rest-reader", "read", "element"), 
  xdmp.permission("rest-writer", "update", "element")
]);
test.assertAtLeastOneEqual(p1, p2)
返回:

[javascript] XDMP-NONMIXEDCOMPLEXCONT: fn:data(<sec:permission 
xmlns:sec="http://marklogic.com/xdmp/security">
<sec:capability>...</sec:capability>...</sec:permission>) 
-- Node has complex type with non-mixed complex content
[javascript]XDMP-nonmixedcomplexcontent:fn:data(
......) 
--节点具有复杂类型和非混合复杂内容

我能想到的最佳选择是显式循环序列,并在每个元素上与
fn.deepEqual
进行比较。有更好的方法吗?

test.assertableastonequal()函数需要原子值(
item()
签名)。唯一可以处理元素的测试助手函数是
test.assertEqualXml()
,但它会查找精确的匹配项。我认为你最好的办法是严格限制权限。大概是这样的:

const test = require("/test/test-helper.xqy");
let p1 = [xdmp.permission("rest-reader", "read")];
let p2 = [
  xdmp.permission("rest-reader", "read"), 
  xdmp.permission("rest-writer", "update")
];
p1 = Sequence.from(p1.map(p => xdmp.roleName(p.roleId) + ':' + p.capability));
p2 = Sequence.from(p2.map(p => xdmp.roleName(p.roleId) + ':' + p.capability));
test.assertAtLeastOneEqual(p1, p2)