From 46421ef6e6b411123e7896fd8d1c572065afee70 Mon Sep 17 00:00:00 2001 From: rdodev Date: Fri, 21 Mar 2014 15:41:42 -0400 Subject: [PATCH 1/5] Leveraging mocha for integration tests. Initial commit. --- config/rackspace.example.json | 6 +-- lib/providers/rackspace/dns/createRecord.js | 2 +- lib/providers/rackspace/dns/createZone.js | 57 +++++++++++++++++---- 3 files changed, 50 insertions(+), 15 deletions(-) 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..74889ad 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', 'rdodev')); client.on('log::*', logging.logFunction); diff --git a/lib/providers/rackspace/dns/createZone.js b/lib/providers/rackspace/dns/createZone.js index 9162dce..f401c68 100644 --- a/lib/providers/rackspace/dns/createZone.js +++ b/lib/providers/rackspace/dns/createZone.js @@ -3,20 +3,55 @@ var pkgcloud = require('pkgcloud'), 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 client = pkgcloud.providers.rackspace.dns.createClient(config.getConfig('rackspace', 2)); +var expect = chai.expect, + should = chai.should(); + +describe('DNS Zone Integration Tests', function () { + describe('createZone', function () { + var client, zoneName, adminEmail, apiUser, tempZone; + -client.on('log::*', logging.logFunction); + before(function (done) { + client = pkgcloud.providers.rackspace.dns.createClient(config.getConfig('rackspace', 'rdodev')); + client.on('log::*', logging.logFunction); + zoneName = 'that.test.computer'; + adminEmail = 'test@test.com'; + done(); + }); -client.createZone( { - name: process.argv[2], - email: process.argv[3] -}, function (err, zone) { - if (err) { - log.error(err); - return; - } + after(function (done) { + client.deleteZone(tempZone, {name: zoneName, email: adminEmail}, function (err) { + if (!err) { + console.log('DNS Zone teardown successful'); + } + done(); + }); + }); - log.info(zone.toJSON()); + 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(); + }); + }); + }); }); \ No newline at end of file From d7fc5be445637f966c591ae79175630e858d3f39 Mon Sep 17 00:00:00 2001 From: rdodev Date: Fri, 21 Mar 2014 15:56:18 -0400 Subject: [PATCH 2/5] Small cleanup. Adding dependencies to package.json --- lib/providers/rackspace/dns/createRecord.js | 2 +- lib/providers/rackspace/dns/createZone.js | 3 +-- package.json | 3 ++- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/providers/rackspace/dns/createRecord.js b/lib/providers/rackspace/dns/createRecord.js index 74889ad..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', 'rdodev')); +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 index f401c68..811f269 100644 --- a/lib/providers/rackspace/dns/createZone.js +++ b/lib/providers/rackspace/dns/createZone.js @@ -21,8 +21,7 @@ describe('DNS Zone Integration Tests', function () { before(function (done) { - client = pkgcloud.providers.rackspace.dns.createClient(config.getConfig('rackspace', 'rdodev')); - client.on('log::*', logging.logFunction); + client = pkgcloud.providers.rackspace.dns.createClient(config.getConfig('rackspace', process.env['PKGCLOUD_TESTS_DEFAULT_USERNAME'])); zoneName = 'that.test.computer'; adminEmail = 'test@test.com'; done(); 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", From e82f09e663b899bc4d6a2f9d90ad22cb06fea76e Mon Sep 17 00:00:00 2001 From: rdodev Date: Fri, 21 Mar 2014 17:04:34 -0400 Subject: [PATCH 3/5] Since I'm grouping tests together depending on API, I renamed the file to be more "semantic". Also added more tests: --- .../dns/{createZone.js => testDnsZone.js} | 55 +++++++++++++------ 1 file changed, 39 insertions(+), 16 deletions(-) rename lib/providers/rackspace/dns/{createZone.js => testDnsZone.js} (51%) diff --git a/lib/providers/rackspace/dns/createZone.js b/lib/providers/rackspace/dns/testDnsZone.js similarity index 51% rename from lib/providers/rackspace/dns/createZone.js rename to lib/providers/rackspace/dns/testDnsZone.js index 811f269..df1830c 100644 --- a/lib/providers/rackspace/dns/createZone.js +++ b/lib/providers/rackspace/dns/testDnsZone.js @@ -16,26 +16,28 @@ var expect = chai.expect, should = chai.should(); describe('DNS Zone Integration Tests', function () { - describe('createZone', function () { - var client, zoneName, adminEmail, apiUser, tempZone; + 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(); - }); - }); + 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', function () { + it('createZone is successful', function (done) { client.createZone({name: zoneName, email: adminEmail}, function (err, zone) { should.not.exist(err); @@ -53,4 +55,25 @@ describe('DNS Zone Integration Tests', function () { }); }); }); + + describe('updateZone', function () { + + it('updateZone should successfully modify Zone', function (done) { + tempZone.emailAddress = 'changed@test.com'; + client.updateZone(tempZone, function (err) { + should.not.exist(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(); + }); + }); + }); + }); \ No newline at end of file From 0bc525e8321b65df2bd4f8fd7a6f19b214143a3d Mon Sep 17 00:00:00 2001 From: rdodev Date: Mon, 24 Mar 2014 14:42:04 -0400 Subject: [PATCH 4/5] Adding additional tests to suite --- lib/providers/rackspace/dns/testDnsZone.js | 29 ++++++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/lib/providers/rackspace/dns/testDnsZone.js b/lib/providers/rackspace/dns/testDnsZone.js index df1830c..61b50e7 100644 --- a/lib/providers/rackspace/dns/testDnsZone.js +++ b/lib/providers/rackspace/dns/testDnsZone.js @@ -10,7 +10,7 @@ var path = require('path'), chai = require('chai'); -var log = logging.getLogger(process.env.PKGCLOUD_LOG_LEVEL || 'debug'); +//var log = logging.getLogger(process.env.PKGCLOUD_LOG_LEVEL || 'debug'); var expect = chai.expect, should = chai.should(); @@ -36,7 +36,7 @@ describe('DNS Zone Integration Tests', function () { }); }); - describe('createZone', function () { + describe('createZone tests', function () { it('createZone is successful', function (done) { client.createZone({name: zoneName, email: adminEmail}, function (err, zone) { @@ -56,18 +56,18 @@ describe('DNS Zone Integration Tests', function () { }); }); - describe('updateZone', function () { + describe('updateZone tests', function () { it('updateZone should successfully modify Zone', function (done) { tempZone.emailAddress = 'changed@test.com'; client.updateZone(tempZone, function (err) { - should.not.exist(err); + if(err) throw err; done(); }); }); it('updateZone should fail', function (done) { - tempZone.emailAddress = "0"; + tempZone.emailAddress = '0'; client.updateZone(tempZone, function (err) { should.exist(err); err.should.be.an('object'); @@ -75,5 +75,24 @@ describe('DNS Zone Integration Tests', function () { }); }); }); + + 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 From 49df38cdd03f38a4cc0022c5275b0d20ade09285 Mon Sep 17 00:00:00 2001 From: rdodev Date: Tue, 25 Mar 2014 12:22:47 -0400 Subject: [PATCH 5/5] Adding new file for DNS record tests. --- lib/providers/rackspace/dns/testDnsRecord.js | 107 +++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 lib/providers/rackspace/dns/testDnsRecord.js 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