diff --git a/config/rackspace.example.json b/config/rackspace.example.json index b3855cc..ad48b0a 100644 --- a/config/rackspace.example.json +++ b/config/rackspace.example.json @@ -1,7 +1,7 @@ { "my-user-name": { - "username": "my-user-name", - "apiKey": "my-api-key", + "username": "user-id", + "apiKey": "482374824hj23h4jk", "provider": "rackspace" } -} \ No newline at end of file +} diff --git a/lib/providers/rackspace/dns/createRecord.js b/lib/providers/rackspace/dns/createRecord.js index ea69cbb..90004fb 100644 --- a/lib/providers/rackspace/dns/createRecord.js +++ b/lib/providers/rackspace/dns/createRecord.js @@ -5,7 +5,7 @@ var pkgcloud = require('pkgcloud'), var log = logging.getLogger(process.env.PKGCLOUD_LOG_LEVEL || 'debug'); -var client = pkgcloud.providers.rackspace.dns.createClient(config.getConfig('rackspace', 4)); +var client = pkgcloud.providers.rackspace.dns.createClient(config.getConfig('rackspace', process.env['PKGCLOUD_TESTS_DEFAULT_USERNAME'])); client.on('log::*', logging.logFunction); diff --git a/lib/providers/rackspace/dns/createZone.js b/lib/providers/rackspace/dns/createZone.js deleted file mode 100644 index 9162dce..0000000 --- a/lib/providers/rackspace/dns/createZone.js +++ /dev/null @@ -1,22 +0,0 @@ -var pkgcloud = require('pkgcloud'), - logging = require('../../../common/logging'), - config = require('../../../common/config'), - _ = require('underscore'); - -var log = logging.getLogger(process.env.PKGCLOUD_LOG_LEVEL || 'debug'); - -var client = pkgcloud.providers.rackspace.dns.createClient(config.getConfig('rackspace', 2)); - -client.on('log::*', logging.logFunction); - -client.createZone( { - name: process.argv[2], - email: process.argv[3] -}, function (err, zone) { - if (err) { - log.error(err); - return; - } - - log.info(zone.toJSON()); -}); \ No newline at end of file diff --git a/lib/providers/rackspace/dns/testDnsRecord.js b/lib/providers/rackspace/dns/testDnsRecord.js new file mode 100644 index 0000000..8c1ff28 --- /dev/null +++ b/lib/providers/rackspace/dns/testDnsRecord.js @@ -0,0 +1,107 @@ +var pkgcloud = require('pkgcloud'), + logging = require('../../../common/logging'), + config = require('../../../common/config'), + _ = require('underscore'); + + +var path = require('path'), + fs = require('fs'), + async = require('async'), + chai = require('chai'); + + +//var log = logging.getLogger(process.env.PKGCLOUD_LOG_LEVEL || 'debug'); + +var expect = chai.expect, + should = chai.should(); + +describe('DNS Record Integration Tests', function () { + + var client, zoneName, adminEmail, apiUser, tempZone; + var recName, recType, recData, tempRec; + + + before(function (done) { + client = pkgcloud.providers.rackspace.dns.createClient(config.getConfig('rackspace', process.env['PKGCLOUD_TESTS_DEFAULT_USERNAME'])), + zoneName = 'that.test.computer', + adminEmail = 'test@test.com', + recName = 'this', + recData = '127.0.0.1', + recType = 'A'; + client.createZone({name: zoneName, email: adminEmail}, function (err, zone) { + should.not.exist(err); + zone.should.be.an('object'); + tempZone = zone; + done(); + }); + }); + + after(function (done) { + client.deleteZone(tempZone, {name: zoneName, email: adminEmail}, function (err) { + if (!err) { + console.log('\nDNS Zone teardown successful'); + } + done(); + }); + }); + + describe('createRecord tests', function () { + + it('createRecord is successful', function (done) { + client.createRecord(tempZone, {name: zoneName, data: recData, type: recType}, function (err, rec) { + should.not.exist(err); + rec.should.be.an('object'); + tempRec = rec; + done(); + }); + }); + + it('createRecord should fail with same params', function (done) { + client.createRecord(tempZone, {name: zoneName, data: recData, type: recType}, function (err, rec) { + should.not.exist(rec); + err.should.be.an('object'); + done(); + }); + }); + }); + + describe('updateRecord tests', function () { + + it('updateRecord should successfully modify Record', function (done) { + tempRec.data = '192.168.0.1'; + client.updateRecord(tempZone, tempRec, function (err) { + if(err) throw err; + done(); + }); + }); + + it('updateRecord should fail', function (done) { + tempRec.data = '0'; + client.updateRecord(tempZone, tempRec, function (err) { + should.exist(err); + err.should.be.an('object'); + done(); + }); + }); + }); + + describe('getRecord tests', function () { + + it('getRecord should retrieve correct record', function (done) { + client.getRecord(tempZone, tempRec.id, function (err, rec) { + rec.id.should.equal(tempRec.id); + should.not.exist(err); + done(); + }); + }); + + it('getRecord should fail not found', function (done) { + client.getRecord(tempZone, 'AW-01010', function (err, rec) { + err.should.be.an('object'); + should.not.exist(rec); + done(); + }); + }); + }); + +}); \ No newline at end of file diff --git a/lib/providers/rackspace/dns/testDnsZone.js b/lib/providers/rackspace/dns/testDnsZone.js new file mode 100644 index 0000000..61b50e7 --- /dev/null +++ b/lib/providers/rackspace/dns/testDnsZone.js @@ -0,0 +1,98 @@ +var pkgcloud = require('pkgcloud'), + logging = require('../../../common/logging'), + config = require('../../../common/config'), + _ = require('underscore'); + + +var path = require('path'), + fs = require('fs'), + async = require('async'), + chai = require('chai'); + + +//var log = logging.getLogger(process.env.PKGCLOUD_LOG_LEVEL || 'debug'); + +var expect = chai.expect, + should = chai.should(); + +describe('DNS Zone Integration Tests', function () { + + var client, zoneName, adminEmail, apiUser, tempZone; + + + before(function (done) { + client = pkgcloud.providers.rackspace.dns.createClient(config.getConfig('rackspace', process.env['PKGCLOUD_TESTS_DEFAULT_USERNAME'])); + zoneName = 'that.test.computer'; + adminEmail = 'test@test.com'; + done(); + }); + + after(function (done) { + client.deleteZone(tempZone, {name: zoneName, email: adminEmail}, function (err) { + if (!err) { + console.log('DNS Zone teardown successful'); + } + done(); + }); + }); + + describe('createZone tests', function () { + + it('createZone is successful', function (done) { + client.createZone({name: zoneName, email: adminEmail}, function (err, zone) { + should.not.exist(err); + zone.should.be.an('object'); + tempZone = zone; + done(); + }); + }); + + it('createZone should fail with same params', function (done) { + client.createZone({name: zoneName, email: adminEmail}, function (err, zone) { + should.not.exist(zone); + err.should.be.an('object'); + done(); + }); + }); + }); + + describe('updateZone tests', function () { + + it('updateZone should successfully modify Zone', function (done) { + tempZone.emailAddress = 'changed@test.com'; + client.updateZone(tempZone, function (err) { + if(err) throw err; + done(); + }); + }); + + it('updateZone should fail', function (done) { + tempZone.emailAddress = '0'; + client.updateZone(tempZone, function (err) { + should.exist(err); + err.should.be.an('object'); + done(); + }); + }); + }); + + describe('getZone tests', function () { + + it('getZone should retrieve correct zone', function (done) { + client.getZone(tempZone.id, function (err, zone) { + zone.id.should.equal(tempZone.id); + should.not.exist(err); + done(); + }); + }); + + it('getZone should fail not found', function (done) { + client.getZone('AW-01010', function (err, zone) { + err.should.be.an('object'); + should.not.exist(zone); + done(); + }); + }); + }); + +}); \ No newline at end of file diff --git a/package.json b/package.json index 44fab02..02a480b 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,8 @@ "async": "0.2.x", "pkgcloud": ">=0.8.17", "commander": "2.1.x", - "easy-table": "0.2.x" + "easy-table": "0.2.x", + "chai": "~1.9.x" }, "license": "MIT", "readmeFilename": "README.md",