forked from elastic/elasticsearch-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed tests for host that were too specific to begin with
- Loading branch information
Spencer Alger
committed
Apr 2, 2014
1 parent
47f0e52
commit b1ee674
Showing
3 changed files
with
37 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,19 +2,23 @@ var Host = require('../../../src/lib/host'); | |
var _ = require('lodash-node'); | ||
var expect = require('expect.js'); | ||
var url = require('url'); | ||
var expectSubObject = require('../../utils/expect_sub_object'); | ||
|
||
var hostDefaults = { | ||
protocol: 'http', | ||
host: 'localhost', | ||
port: 9200, | ||
path: '', | ||
auth: null, | ||
query: {}, | ||
headers: null | ||
}; | ||
|
||
describe('Host class', function () { | ||
describe('construction', function () { | ||
it('properly sets the defaults', function () { | ||
var host = new Host(); | ||
expect(host).to.eql({ | ||
protocol: 'http', | ||
host: 'localhost', | ||
port: 9200, | ||
path: '', | ||
auth: null, | ||
query: {} | ||
}); | ||
expect(host).to.eql(hostDefaults); | ||
}); | ||
|
||
it('accepts a string for query', function () { | ||
|
@@ -36,7 +40,7 @@ describe('Host class', function () { | |
it('accepts a string for the entire url', function () { | ||
var host = new Host('john:[email protected]:420/pizza/cheese?shrooms=true'); | ||
|
||
expect(host).to.eql({ | ||
expectSubObject(host, { | ||
protocol: 'http', | ||
host: 'pizza.com', | ||
port: 420, | ||
|
@@ -95,14 +99,7 @@ describe('Host class', function () { | |
it('ignores anything that\'s not a string or object-y', function () { | ||
var host = new Host(1234); | ||
|
||
expect(host).to.eql({ | ||
protocol: 'http', | ||
host: 'localhost', | ||
port: 9200, | ||
path: '', | ||
auth: null, | ||
query: {} | ||
}); | ||
expect(host).to.eql(hostDefaults); | ||
}); | ||
}); | ||
|
||
|
@@ -121,7 +118,7 @@ describe('Host class', function () { | |
param: 1 | ||
}, | ||
auth: 'user:pass' | ||
})).to.be('http://user:pass@localhost:9200/prefix/this and that?param=1&user_id=123'); | ||
})).to.be('http://user:pass@localhost:9200/prefix/this and that?user_id=123¶m=1'); | ||
}); | ||
|
||
it('ensures that path starts with a forward-slash', function () { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
var _ = require('lodash-node'); | ||
var expect = require('expect.js'); | ||
module.exports = function expectSubObject(obj, subObj) { | ||
_.forOwn(subObj, function (val, prop) { | ||
if (typeof obj[prop] === 'object') { | ||
// non-strict equals | ||
expect(obj[prop]).to.eql(val, 'Expected property' + prop + ' of object to equal ' + val); | ||
} else { | ||
expect(obj).property(prop, val); | ||
} | ||
}); | ||
}; |