Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leveraging Mocha for integration tests #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions config/rackspace.example.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"my-user-name": {
"username": "my-user-name",
"apiKey": "my-api-key",
"username": "user-id",
"apiKey": "482374824hj23h4jk",
"provider": "rackspace"
}
}
}
2 changes: 1 addition & 1 deletion lib/providers/rackspace/dns/createRecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
22 changes: 0 additions & 22 deletions lib/providers/rackspace/dns/createZone.js

This file was deleted.

107 changes: 107 additions & 0 deletions lib/providers/rackspace/dns/testDnsRecord.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
});

});
98 changes: 98 additions & 0 deletions lib/providers/rackspace/dns/testDnsZone.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
});

});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down