apiaryio / dredd

Language-agnostic HTTP API Testing Tool
https://dredd.org
MIT License
4.18k stars 278 forks source link

Dredd - API Blueprint Testing Tool. “Undefined” while testing #47

Closed imp-partner-test closed 10 years ago

imp-partner-test commented 10 years ago

I installed dredd - API Blueprint Testing Tool and trying to test our APIary API against the implementation. In the blueprint I have just one resource which is correctly implemented on somehost... but test fails :(

test command: dredd apiary.apib http://somehost.de:8443/imp-endpoint output: Info: Beginning Dredd testing... undefined

I tried also with more options to get more information what is undefined.. like -l verbose and some other options. But I did not get more information about the failure :( Does anyone have experience with it? Thank you!!! :)


platform - win, dredd - v0.2.1, test apib: https://www.dropbox.com/s/p9zexrj3g6htzlq/apiary.apib, test.sh: https://www.dropbox.com/s/vqn6gch91vwqc16/test.sh on stackoverflow: http://stackoverflow.com/questions/21881988/dredd-api-blueprint-testing-tool-undefined-issue

ecordell commented 10 years ago

Couple of things:

  1. At the moment, the base url can't have a path in it (see #43). This is solved in #45 but hasn't yet been merged. So your command should be 'dredd apiary.apib http://somehost.de:8443/' and then '/imp-endpoint' should be a prefix on the urls.
  2. The URI template is incorrect in your apib file. Instead of /api/V0/Resources/CarSharing/Cars?{lat}&{lng}&{radius}, it should be /imp-endpoint/api/V0/Resources/CarSharing/Cars{?lat,lng,radius}. See RFC6750 for reference.
  3. The line-endings should be Unix style, not Windows (\n, not \n\r). When I first ran the apib you provided, I got the error: the use of carriage return(s) '\r' in source data isn't currently supported, please contact makers (this is actually enforced by the blueprint parser, see snowcrash)

I wasn't able to to reproduce your "undefined" problem. When making the changes above, however, I got the following output:

Fail: GET /imp-endpoint/api/V0/Resources/CarSharing/Cars?lat=52.52&lng=13.39&radius=1000

Message

headers: Value of the ‘content-type’ must be application/hal+json.
body: No validator found for real data media type 'text/plain' and expected data media type 'application/json'.

Request

body: 

headers: 
    User-Agent: Dredd/0.3.0 (Darwin 13.0.0; x64)

uri: /imp-endpoint/api/V0/Resources/CarSharing/Cars?lat=52.52&lng=13.39&radius=1000
method: GET

Expected

headers: 
    Content-Type: application/hal+json

body: 
[
    {
        "actions": [
            {
                "name": "book",
                "method": "POST",
                "uri": "Resources/CarSharing/Cars/215992/Process?action=book"
            }
        ],
        "id": 215992,
        "description": "B-GO3336",
        "type": "CarSharingCar",
        "uri": "Resources/CarSharing/Cars/215992",
        "location": {
            "latitude": 52.51138,
            "longitude": 13.39313,
            "system": "WGS_84"
        },
        "provider": "Car2Go_Berlin",
        "operator": "Car2Go_Berlin",
        "address": {
            "citycode": null,
            "city": null,
            "street": "Kronenstra�e 24, 10117 Berlin",
            "houseno": null,
            "district": null,
            "region": null,
            "country": null
        },
        "licenseId": "B-GO3336",
        "category": null,
        "fuelType": "PETROL",
        "imageLink": null
    },
    {
        "actions": [
            {
                "name": "book",
                "method": "POST",
                "uri": "Resources/CarSharing/Cars/215993/Process?action=book"
            }
        ],
        "id": 215993,
        "description": "B-GO2356",
        "type": "CarSharingCar",
        "uri": "Resources/CarSharing/Cars/215993",
        "location": {
            "latitude": 52.52053,
            "longitude": 13.39428,
            "system": "WGS_84"
        },
        "provider": "Car2Go_Berlin",
        "operator": "Car2Go_Berlin",
        "address": {
            "citycode": null,
            "city": null,
            "street": "Stadtbahnbogen 177 - 182, 10117 Berlin (Umkreis 100m)",
            "houseno": null,
            "district": null,
            "region": null,
            "country": null
        },
        "licenseId": "B-GO2356",
        "category": null,
        "fuelType": "PETROL",
        "imageLink": null
    },
    {
        "actions": [
            {
                "name": "book",
                "method": "POST",
                "uri": "Resources/CarSharing/Cars/215994/Process?action=book"
            }
        ],
        "id": 215994,
        "description": "B-GO2733",
        "type": "CarSharingCar",
        "uri": "Resources/CarSharing/Cars/215994",
        "location": {
            "latitude": 52.51228,
            "longitude": 13.39639,
            "system": "WGS_84"
        },
        "provider": "Car2Go_Berlin",
        "operator": "Car2Go_Berlin",
        "address": {
            "citycode": null,
            "city": null,
            "street": "Jerusalemer Stra�e 27, 10117 Berlin",
            "houseno": null,
            "district": null,
            "region": null,
            "country": null
        },
        "licenseId": "B-GO2733",
        "category": null,
        "fuelType": "PETROL",
        "imageLink": null
    },
    {
        "actions": [
            {
                "name": "book",
                "method": "POST",
                "uri": "Resources/CarSharing/Cars/215995/Process?action=book"
            }
        ],
        "id": 215995,
        "description": "B-GO3325",
        "type": "CarSharingCar",
        "uri": "Resources/CarSharing/Cars/215995",
        "location": {
            "latitude": 52.51299,
            "longitude": 13.38648,
            "system": "WGS_84"
        },
        "provider": "Car2Go_Berlin",
        "operator": "Car2Go_Berlin",
        "address": {
            "citycode": null,
            "city": null,
            "street": "Glinkastra�e 19, 10117 Berlin",
            "houseno": null,
            "district": null,
            "region": null,
            "country": null
        },
        "licenseId": "B-GO3325",
        "category": null,
        "fuelType": "PETROL",
        "imageLink": null
    }
]

status: 200

Actual

headers: 
    server: nginx/1.4.1
    date: Thu, 27 Feb 2014 14:53:41 GMT
    content-type: text/html
    content-length: 1073
    connection: keep-alive
    x-powered-by: Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1.2.2 Java/Oracle Corporation/1.7)
    pragma: No-cache
    cache-control: no-cache
    expires: Thu, 01 Jan 1970 01:00:00 CET
    www-authenticate: Basic realm="imp-realm"

body: 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

  <head>
    <title>GlassFish Server Open Source Edition 3.1.2.2 - Error report</title>
    <style
    type="text/css">
      <!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;}
      H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;}
      H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;}
      BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;}
      B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;}
      P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A
      {color : black;}HR {color : #525D76;}-->
      </style>
  </head>

  <body>
    <h1>HTTP Status 401 - </h1>
    <hr/>
    <p><b>type</b> Status report</p>
    <p><b>message</b>
    </p>
    <p><b>description</b>This request requires HTTP authentication ().</p>
    <hr/>
    <h3>GlassFish Server Open Source Edition 3.1.2.2</h3>
  </body>

</html>
status: 401
imp-partner-test commented 10 years ago

Hi Evan, thank you. I removed the \r from the test.sh. and changed the blueprint as you described. I'm still getting the undefined :( I'm running dredd on Windows, in cmd and on Cyqwin. And i get this undefined even if do provide a dummy host... I connected API to github. And pulled the apiary.apib from github... so there are no \r\n characters.

Please find the screenshot of it and files I'm working with now in the attachment. thank you, Oxana

https://www.dropbox.com/s/p9zexrj3g6htzlq/apiary.apib https://www.dropbox.com/s/vqn6gch91vwqc16/test.sh https://www.dropbox.com/s/xckrn6x99a2bllv/undefined.png https://www.dropbox.com/s/07qkiexeph49oos/Untitled2.png

ecordell commented 10 years ago

What version of dredd are you using? (dredd --version)

imp-partner-test commented 10 years ago

dredd - v0.2.1 on windows. you ran the tests above with v0.3.0. How can I get this version? It seems not to be available..

imp-partner-test commented 10 years ago

Could you please kindly try to run the version v0.2.1 on windows? I'm curious if it is the versions problem or maybe there is smth wrong with my installation.

zdne commented 10 years ago

@imp-partner-test I will try it and keep you posted.

ecordell commented 10 years ago

I've been putting in a little time on this issue here and there when I can.

Good news: I've got a windows vm running with dredd 0.2.1 and I can reproduce your problem.

Bad news: I can't easily test why it's happening because all of the build tools are written for mac/linux. So a fix will take a little more time.

ecordell commented 10 years ago

Today, I booted up the windows vm, downloaded the apib from the dropbox link, converted it to unix line endings, and dredd worked as expected.

I thought I had narrowed it down, but everything is working now. Can no longer reproduce the undefined.

zdne commented 10 years ago

@ecordell I can reproduce it right now. Do you have any pointers where I can look?

C:\Users\zdenek\Documents\GitHub\dredd [master +1 ~0 -0 !]> dredd .\apiary.apib.txt https://as.production.imp.mobilitaetsdienste.de:8443/
info: Beginning Dredd testing...
undefined
C:\Users\zdenek\Documents\GitHub\dredd [master +1 ~0 -0 !]>
zdne commented 10 years ago

OK I have updated to latest Dredd (v0.3.0) and removed the \r line endings (using just \n) and it seems to work, albeit I do not know whether it is because of v0.3.0.

@imp-partner-test can you still reproduce the problem with Dredd v0.3.0 and unix line endings?

C:\Users\zdenek\Documents\GitHub\dredd [master +1 ~0 -0 !]> dredd .\apiary.apib.txt https://as.production.imp.mobilitaetsdienste.de:8443/
info: Beginning Dredd testing...
warn: Runtime compilation warning:
Ambigous URI template: /imp-endpoint/api/V0/Resouces/CaShaing/Cas?{lat,lng,adius}
Parameter not defined:'lat'
 on  > Getting fee-floating Cas > Getting fee-floating Cas Action
warn: Runtime compilation warning:
Ambigous URI template: /imp-endpoint/api/V0/Resouces/CaShaing/Cas?{lat,lng,adius}
Parameter not defined:'lng'
 on  > Getting fee-floating Cas > Getting fee-floating Cas Action
warn: Runtime compilation warning:
Ambigous URI template: /imp-endpoint/api/V0/Resouces/CaShaing/Cas?{lat,lng,adius}
Parameter not defined:'adius'
 on  > Getting fee-floating Cas > Getting fee-floating Cas Action
complete: Tests took 32ms
imp-partner-test commented 10 years ago

@zdne, @ecordell I updated dredd to v0.3.0 and removed the \r stuff. Now it works. Thank you!!

netmilk commented 10 years ago

So the summary is:

Given I'm on Windows system And I have some API blueprint with CR+LF line endings And I have dredd 'v0.3.0' package installed When I run Dredd Then I get the undefined message And no test is performed

Am I right? Adam

imp-partner-test commented 10 years ago

It used to be... After the last update of dredd v0.3.0 package I get the warning: "the use of carriage return(s) '\r' in source data isn't currently supported, please contact makers" in case the tested apiary blueprint contains \r in like endings

netmilk commented 10 years ago

It seems that CR+LF line endings are not suported in Sundown, markdown parser used by Snowcrash API Blueprint parser. So this is a Snowcrash issue.

awesome commented 8 years ago

FWIW: Had this issue and fixed it with: https://www.npmjs.com/package/gulp-convert-newline . Formatted lined endings like:

'use strict';

var gulp = require('gulp'),
  concat = require('gulp-concat'),
  config = require('./config/apib_config.js'),
  // […]
  soften = require('gulp-soften'),
  template = require('gulp-template'),
  convertNewline = require("gulp-convert-newline");

var srcDir = './src/**/*.apib',
  outDir = './build/',
  outFile = 'output.apib';

gulp.task('main', function() {
  gulp.src(srcDir)
    .pipe(template(config))
    .pipe(soften(4))
    .pipe(concat('output.apib'))

    .pipe(convertNewline({
      newline: "lf"
    }))

    .pipe(gulp.dest('./build/'));
});