Skip to content

Commit

Permalink
use ifError
Browse files Browse the repository at this point in the history
  • Loading branch information
floatdrop committed Sep 17, 2015
1 parent dae809b commit 3f46b65
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 41 deletions.
4 changes: 2 additions & 2 deletions test/test-arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ test('arguments - url argument is required', function (t) {

test('arguments - accepts url.parse object as first argument', function (t) {
got({hostname: s.host, port: s.port, path: '/test'}, function (err, data) {
t.error(err);
t.ifError(err);
t.is(data, '/test');
t.end();
});
});

test('arguments - overrides querystring from opts', function (t) {
got(s.url + '/?test=doge', {query: {test: 'wow'}}, function (err, data) {
t.error(err);
t.ifError(err);
t.is(data, '/?test=wow');
t.end();
});
Expand Down
4 changes: 2 additions & 2 deletions test/test-gzip.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ test.before('gzip - setup', function (t) {

test('gzip - ungzip content', function (t) {
got(s.url, function (err, data) {
t.error(err);
t.ifError(err);
t.is(data, testContent);
t.end();
});
Expand All @@ -48,7 +48,7 @@ test('gzip - ungzip error', function (t) {

test('gzip - preserve headers property', function (t) {
got(s.url, function (err, data, res) {
t.error(err);
t.ifError(err);
t.ok(res.headers);
t.end();
});
Expand Down
10 changes: 5 additions & 5 deletions test/test-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test.before('headers - setup', function (t) {

test('headers - send user-agent header by default', function (t) {
got(s.url, function (err, data) {
t.error(err);
t.ifError(err);

var headers = JSON.parse(data);

Expand All @@ -27,7 +27,7 @@ test('headers - send user-agent header by default', function (t) {

test('headers - send accept-encoding header by default', function (t) {
got(s.url, function (err, data) {
t.error(err);
t.ifError(err);

var headers = JSON.parse(data);

Expand All @@ -38,15 +38,15 @@ test('headers - send accept-encoding header by default', function (t) {

test('headers - send accept header with json option', function (t) {
got(s.url, {json: true}, function (err, headers) {
t.error(err);
t.ifError(err);
t.is(headers.accept, 'application/json');
t.end();
});
});

test('headers - send host header by default', function (t) {
got(s.url, function (err, data) {
t.error(err);
t.ifError(err);

var headers = JSON.parse(data);

Expand All @@ -57,7 +57,7 @@ test('headers - send host header by default', function (t) {

test('headers - transform headers names to lowercase', function (t) {
got(s.url, {headers: {'USER-AGENT': 'test'}}, function (err, data) {
t.error(err);
t.ifError(err);

var headers = JSON.parse(data);

Expand Down
2 changes: 1 addition & 1 deletion test/test-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test.before('helpers - setup', function (t) {

test('helpers - callback mode', function (t) {
got.get(s.url, function (err, data) {
t.error(err);
t.ifError(err);
t.is(data, 'ok');
t.end();
});
Expand Down
12 changes: 6 additions & 6 deletions test/test-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,23 @@ test.before('http - setup', function (t) {

test('http - callback mode', function (t) {
got(s.url, function (err, data) {
t.error(err);
t.ifError(err);
t.is(data, 'ok');
t.end();
});
});

test('http - protocol-less URLs', function (t) {
got(s.url.replace(/^http:\/\//, ''), function (err, data) {
t.error(err);
t.ifError(err);
t.is(data, 'ok');
t.end();
});
});

test('http - empty response', function (t) {
got(s.url + '/empty', function (err, data) {
t.error(err);
t.ifError(err);
t.is(data, '');
t.end();
});
Expand All @@ -64,7 +64,7 @@ test('http - error with code', function (t) {

test('http - buffer on encoding === null', function (t) {
got(s.url, {encoding: null}, function (err, data) {
t.error(err);
t.ifError(err);
t.ok(Buffer.isBuffer(data));
t.end();
});
Expand All @@ -81,12 +81,12 @@ test('http - query option', function (t) {
t.plan(4);

got(s.url, {query: {recent: true}}, function (err, data) {
t.error(err);
t.ifError(err);
t.is(data, 'recent');
});

got(s.url, {query: 'recent=true'}, function (err, data) {
t.error(err);
t.ifError(err);
t.is(data, 'recent');
});
});
Expand Down
10 changes: 5 additions & 5 deletions test/test-https.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test.before('https - create root pem', function (t) {
days: 1,
selfSigned: true
}, function (err, keys) {
t.error(err);
t.ifError(err);
caRootKey = keys.serviceKey;
caRootCert = keys.certificate;
t.end();
Expand All @@ -35,7 +35,7 @@ test.before('https - create pem', function (t) {
organizationUnit: '',
commonName: 'sindresorhus.com'
}, function (err, keys) {
t.error(err);
t.ifError(err);
key = keys.clientKey;
cert = keys.certificate;
t.end();
Expand All @@ -59,7 +59,7 @@ test.before('https - setup', function (t) {

test('https - redirects from http to https works', function (t) {
got('http://github.com', function (err, data) {
t.error(err);
t.ifError(err);
t.ok(data);
t.end();
});
Expand All @@ -69,7 +69,7 @@ test('https - make request to https server', function (t) {
got('https://google.com', {
strictSSL: true
}, function (err, data) {
t.error(err);
t.ifError(err);
t.ok(data);
t.end();
});
Expand All @@ -81,7 +81,7 @@ test('https - make request to https server with ca', function (t) {
ca: caRootCert,
headers: {host: 'sindresorhus.com'}
}, function (err, data) {
t.error(err);
t.ifError(err);
t.is(data, 'ok');
t.end();
});
Expand Down
4 changes: 2 additions & 2 deletions test/test-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ test.before('json - setup', function (t) {

test('json - json option should parse response', function (t) {
got(s.url, {json: true}, function (err, json) {
t.error(err);
t.ifError(err);
t.same(json, {data: 'dog'});
t.end();
});
});

test('json - json option should not parse responses without a body', function (t) {
got(s.url + '/204', {json: true}, function (err) {
t.error(err);
t.ifError(err);
t.end();
});
});
Expand Down
24 changes: 12 additions & 12 deletions test/test-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ test.before('post - setup', function (t) {
// });
//
// got.get(s.url + '/method', {body: stream}, function (err, data, res) {
// t.error(err);
// t.ifError(err);
// t.is(res.headers.method, 'GET');
// });
// });
Expand All @@ -48,24 +48,24 @@ test('post - send data from options with post request', function (t) {
t.plan(6);

got(s.url, {body: 'wow'}, function (err, data) {
t.error(err);
t.ifError(err);
t.is(data, 'wow');
});

got(s.url, {body: new Buffer('wow')}, function (err, data) {
t.error(err);
t.ifError(err);
t.is(data, 'wow');
});

got(s.url, {body: intoStream(['wow'])}, function (err, data) {
t.error(err);
t.ifError(err);
t.is(data, 'wow');
});
});

test('post - works with empty post response', function (t) {
got(s.url + '/empty', {body: 'wow'}, function (err, data) {
t.error(err);
t.ifError(err);
t.is(data, '');
t.end();
});
Expand All @@ -75,27 +75,27 @@ test('post - post have content-length header to string', function (t) {
t.plan(10);

got(s.url + '/headers', {body: 'wow', json: true}, function (err, headers) {
t.error(err);
t.ifError(err);
t.is(headers['content-length'], '3');
});

got(s.url + '/headers', {body: new Buffer('wow'), json: true}, function (err, headers) {
t.error(err);
t.ifError(err);
t.is(headers['content-length'], '3');
});

got(s.url + '/headers', {body: intoStream(['wow']), json: true}, function (err, headers) {
t.error(err);
t.ifError(err);
t.is(headers['content-length'], undefined);
});

got(s.url + '/headers', {body: 'wow', json: true, headers: {'content-length': '10'}}, function (err, headers) {
t.error(err);
t.ifError(err);
t.is(headers['content-length'], '10');
});

got(s.url + '/headers', {body: '3\r\nwow\r\n0\r\n', json: true, headers: {'transfer-encoding': 'chunked'}}, function (err, headers) {
t.error(err);
t.ifError(err);
t.is(headers['content-length'], undefined);
});
});
Expand All @@ -104,12 +104,12 @@ test('post - works with plain object in body', function (t) {
t.plan(4);

got(s.url, {body: {such: 'wow'}}, function (err, data) {
t.error(err);
t.ifError(err);
t.is(data, 'such=wow');
});

got(s.url + '/headers', {headers: {'content-type': 'doge'}, body: {such: 'wow'}, json: true}, function (err, headers) {
t.error(err);
t.ifError(err);
t.is(headers['content-type'], 'doge');
});
});
Expand Down
8 changes: 4 additions & 4 deletions test/test-redirects.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ test.before('redirects - setup', function (t) {

test('redirects - follows redirect', function (t) {
got(s.url + '/finite', function (err, data) {
t.error(err);
t.ifError(err);
t.is(data, 'reached');
t.end();
});
});

test('redirects - follows relative redirect', function (t) {
got(s.url + '/relative', function (err, data) {
t.error(err);
t.ifError(err);
t.is(data, 'reached');
t.end();
});
Expand All @@ -68,15 +68,15 @@ test('redirects - throws on endless redirect', function (t) {

test('redirects - query in options are not breaking redirects', function (t) {
got(s.url + '/relativeQuery', {query: 'bang'}, function (err, data) {
t.error(err);
t.ifError(err);
t.is(data, 'reached');
t.end();
});
});

test('redirects - hostname+path in options are not breaking redirects', function (t) {
got(s.url + '/relative', {hostname: s.host, path: '/relative'}, function (err, data) {
t.error(err);
t.ifError(err);
t.is(data, 'reached');
t.end();
});
Expand Down
4 changes: 2 additions & 2 deletions test/test-unix-socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test('unix-socket - request via unix socket', function (t) {
var url = format('http://unix:%s:%s', socketPath, '/');

got(url, function (err, data) {
t.error(err);
t.ifError(err);
t.is(data, 'ok');
t.end();
});
Expand All @@ -33,7 +33,7 @@ test('unix-socket - protocol-less request', function (t) {
var url = format('unix:%s:%s', socketPath, '/');

got(url, function (err, data) {
t.error(err);
t.ifError(err);
t.is(data, 'ok');
t.end();
});
Expand Down

0 comments on commit 3f46b65

Please sign in to comment.