UNPKG

racker

Version:

Robust Rackspace cloudfiles client

65 lines (54 loc) 1.99 kB
var util = require('..').util , hosts = require('..').hosts; describe('util', function () { describe('.merge', function () { it('should merge two objs', function () { util.merge({}, hosts).should.eql(hosts); util.merge({}, hosts).should.not.equal(hosts); }) }) describe('.host', function () { it('should return the full host url if a shortcut is given', function () { util.host('us').should.eql(hosts.us); util.host('uk').should.eql(hosts.uk); }) it('should return the given host if the host isn\'t a shortcut', function () { util.host('foo').should.eql('foo'); }) }) describe('.error', function () { it('should return a new Error', function () { util.error({ status: 404 }).should.be.instanceOf(Error); }) it('should set the error message to the status code', function () { util.error({ status: 404 }).message.should.eql('Not Found'); }) it('should put the given res in `err.res`', function () { var res = { status: 404 }; util.error(res).res.should.equal(res); }) }) describe('.capitalize', function () { it('should capitalize', function () { util.capitalize('foo').should.eql('Foo'); }) }) describe('.headerize', function () { it('should headerize', function () { util.headerize('foo-bar').should.eql('Foo-Bar'); util.headerize(' foo - bar').should.eql('Foo-Bar'); }) }) describe('.metas', function () { it('should convert the given metas to headers', function () { util.metas({ foo: 'bar' }).should.eql({ 'X-Container-Meta-Foo': 'bar' }); }) }) describe('.convert', function () { it('should return an obj of metas from the given heads', function () { util.convert({ 'X-Container-Meta-Foo': 'bar' }).should.eql({ foo: 'bar' }); util.convert({ 'X-Object-Meta-Foo-Bar': 'bar' }).should.eql({ 'foo bar': 'bar' }); util.convert({ host: 'bar' }).should.eql({}); }) }) })