APIary的Dredd测试调用返回图像/ PNG

时间:2014-07-18 12:18:33

标签: apiary.io apiary dredd

返回图像/ PNG的APIary调用的Dredd测试失败。是否可以检查返回图像的内容,而只是检查图像不是null作为响应?

以下是我测试的输出:

 [31mfail [39m: GET /imp-endpoint/api/V1/Resources?left_lower_lat=52.482780222078205&left_lower_lng=13.3154296875&right_upper_lng=13.359375&right_upper_lat=52.50953477032729&width=250&heigth=250 duration: 1176ms
 [31mfail [39m: body: Real and expected data does not match.

 [32mrequest [39m: 
body: 

headers: 
    accept: image/png
    User-Agent: Dredd/0.3.7 (Linux 3.5.0-52-generic; ia32)
    Authorization: Basic ZG1wOmRtcEAxMjM0

uri: /imp-endpoint/api/V1/Resources?left_lower_lat=52.482780222078205&left_lower_lng=13.3154296875&right_upper_lng=13.359375&right_upper_lat=52.50953477032729&width=250&heigth=250
method: GET


 [31mexpected [39m: 
headers: 
    content-type: image/png

body: 
�PNG

statusCode: 200


 [31mactual [39m: 
statusCode: 200
headers: 
    x-powered-by: Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1.2.2 Java/Oracle Corporation/1.7)
    server: GlassFish Server Open Source Edition 3.1.2.2
    access-control-allow-origin: *
    access-control-allow-methods: GET, POST, PUT, DELETE, OPTIONS
    content-type: image/png
    content-length: 26572
    date: Tue, 15 Jul 2014 09:00:26 GMT

body: 
�PNG


IHDR    � ?1g�IDATx^��

2 个答案:

答案 0 :(得分:0)

这是known limitation。正如Adam在链接页面上所述,目前不支持API Blueprint格式的二进制blob,也不能用于使用Dredd进行测试。

我们(Apiary)计划在蓝图中正确支持二进制文件,但在它发生之前,我们应该为API提供一种传递验证的方法。

作为一个毛茸茸的解决方法,您可以指定空的HTTP正文和正确的Content-Length标题,以便省略对正文的测试。

答案 1 :(得分:0)

作为解决方法,您可以使用:

hooks.beforeValidation('User > Avatar > Get Mine', function (transaction) {
  transaction.expected.headers['content-length'] = 9999;
  transaction.real.body = '';
});

甚至,在蓝图上设置内容长度标题,如下所示:

+ Response 200 (image/png)

    + Headers

        Content-Length: 26572