vowsjs / api-easy

Fluent (i.e. chainable) syntax for generating vows tests against RESTful APIs.
http://flatiron.github.com/api-easy
MIT License
425 stars 37 forks source link

Permission denied when running the test #53

Open tciuro opened 11 years ago

tciuro commented 11 years ago

Hi,

I've tried to follow the instructions, but I keep on getting a "Permission denied" error:

Macintosh:foo tito$ npm test
npm WARN package.json foo@0.0.1 No repository field.
npm WARN package.json foo@0.0.1 No readme data.

> foo@0.0.1 test /Users/tito/Desktop/FooDevelopment/foo
> tests/*-test.js

sh: tests/connect-test.js: Permission denied
npm ERR! weird error 126
npm ERR! not ok code 0
Macintosh:foo tito$ 

I'm not sure what's wrong. This is what tests/connect-test.js looks like:

var APIeasy = require('api-easy');
var suite = APIeasy.describe('your/awesome/api');

suite.discuss('When using your awesome API')
  .discuss('and your awesome resource')
  .use('localhost', 8080)
  .setHeader('Content-Type', 'application/json')
  .post('/connection')
  .expect(200)
.export(module);

The permissions look like this

-rw-r--r--   1 tito  staff  2311 Jul  7 20:39 connect-test.js

Any ideas? Thanks!

indexzero commented 11 years ago

Maybe you don't have permission to listen on that port? What is the code you're testing?

tciuro commented 11 years ago

It's a node.js server that's working fine (I'm actually testing it with Objective-C and Chrome's Dev HTTP Client utility. I'm running on port 8080 without issues:

9 Jul 00:09:02 - [nodemon] starting `node app.js localhost 8080`
Express HTTP server listening on port 8080

Assuming that the server is running fine, the above code would report a 403 as opposed to permission denied, right? Or is this permission denied the result of an HTTP 403? (which the server returns if no authentication has succeeded)

Thank you.

tciuro commented 11 years ago

I'm having no trouble at all performing the invocation from the browser. Weird...

tciuro commented 11 years ago

OK, somehow I got it to work (I've tried so many things I'm not sure what made it work.) This is the dummy test I setup in place:

function showStats(req, res) {

  log.info('GET /admin/stats');

  var someValue = '12345';
  res.writeHead(200, {
    'Content-Type': 'application/json',
  });
  res.write(JSON.stringify({
    someValue: someValue
  }));
  return res.end();
}

module.exports.initialize = function (app) {
  app.get('/admin/stats', showStats);
};

This is the test:

var APIeasy = require('api-easy'),
  assert = require('assert');

var suite = APIeasy.describe('your/awesome/api');

suite.discuss('When using your awesome API')
  .discuss('and your awesome resource')
  .use('localhost', 8080)
  .setHeader('Content-Type', 'application/json')
  .get('/admin/stats')
  .expect(200)
  .export(module);

When I call npm test, I get the following:

Macintosh:fooTest tito$ npm test
npm WARN package.json fooTest@0.0.1 No repository field.
npm WARN package.json fooTest@0.0.1 No readme data.

> fooTest@0.0.1 test /Users/tito/Desktop/fooTest
> vows test/*-test.js

✗  

    When using your awesome API and your awesome resource A GET to /admin/stats 
      ✗ should respond with 200 
        » expected 200, 
    got  400 (==) // api-easy.js:290 
  ✗ Broken » 1 broken (1.330s) 
  npm ERR! weird error 1
npm ERR! not ok code 0
Macintosh:fooTest tito$ 

How in the world is it getting a 400? It's impossible! Again, if I invoke it via http://localhost:8080/admin/stats I get back:

{
    "someValue":"12345"
}

Even Charles proxy shows that the response is a 200. What gives?