2014-07-18 35 views
3

返回圖像/ PNG的APIary調用的分揀測試失敗。是否有可能不檢查返回的圖像的內容,而只是有一個圖像不是空作爲響應?返回圖像的APIary調用的分揀測試/ PNG

這裏是我的測試的輸出:

[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^�� 

回答

0

這是一個known limitation。正如Adam在鏈接頁面上所述,此時API Blueprint格式不支持二進制blob,因此不能用於使用Dredd進行測試。

我們(養蜂場)計劃實際上在藍圖中正確支持二進制文件,但在它發生之前,確實應該爲API提供一種方法來通過驗證。

作爲一個多毛的解決方法,您可以指定空的HTTP正文和正確的Content-Length標題,以便省略正文的測試。

+0

這種行爲似乎的Dredd已經改變,因爲這是書面。指定一個空的正文+正確的內容長度標題仍然會導致Dredd失敗。 Apiary測試網站中的錯誤消息顯示爲「真實和預期數據不匹配」。在「身體」上。 –

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 
+0

現在,我正在尋找一個POST請求發送圖像的示例...:P – leomperes