Skip to content

Commit

Permalink
feat(semver): add checks for libvirt version in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Aug 17, 2015
1 parent 5e8f684 commit d035f6b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 20 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"mocha": "^2.2.1",
"chai": "^2.2.0",
"segfault-handler": "^0.2.4",
"jshint": "^2.6.0"
"jshint": "^2.6.0",
"semver": "^5.0.1"
}
}
43 changes: 31 additions & 12 deletions test/domain.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
var libvirt = require('../lib'),
Hypervisor = libvirt.Hypervisor,
SegfaultHandler = require('segfault-handler'),
fixture = require('./lib/helper').fixture,
h = require('./lib/helper'),
semver = require('semver'),
expect = require('chai').expect;

var test = {};
describe('Domain', function() {
before(function() {
SegfaultHandler.registerHandler();
return h.getLibVirtVersion()
.then(function(version) {
test.version = version;
});
});

describe('hypervisor methods', function() {
Expand Down Expand Up @@ -37,7 +42,7 @@ describe('Domain', function() {
});

it('should create a persistent Domain from its XML Description', function(done) {
var xml = fixture('domain.xml');
var xml = h.fixture('domain.xml');
test.hypervisor.createDomain(xml, function(err, domain) {
expect(err).to.not.exist;
expect(domain).to.exist;
Expand All @@ -60,7 +65,7 @@ describe('Domain', function() {
});

it('should {,un}define a persistent Domain', function(done) {
var xml = fixture('domain.xml');
var xml = h.fixture('domain.xml');
test.hypervisor.defineDomain(xml, function(err, domain) {
expect(err).to.not.exist;
expect(domain).to.exist;
Expand Down Expand Up @@ -178,7 +183,9 @@ describe('Domain', function() {
});

it('should save a managed image of the domain', function(done) {
// NOTE: test driver doesn't support these functions
if (semver.lt(test.version, '1.0.0')) { return done(); }

// NOTE: test driver doesn't support these functions in 0.9.x
test.domain.managedSave(function(err, saved) {
expect(err).to.not.exist;
expect(saved).to.be.true;
Expand All @@ -192,6 +199,8 @@ describe('Domain', function() {
});

it('should remove a managed image of the domain', function(done) {
if (semver.lt(test.version, '1.0.0')) { return done(); }

test.domain.managedSave(function(err, saved) {
expect(err).to.not.exist;
expect(saved).to.be.true;
Expand Down Expand Up @@ -221,7 +230,7 @@ describe('Domain', function() {
});

it('should attach a device', function(done) {
var xml = fixture('device.xml');
var xml = h.fixture('device.xml');
test.domain.attachDevice(xml, function(err, result) {
expect(err).to.exist;

Expand All @@ -234,7 +243,7 @@ describe('Domain', function() {
});

it('should detach a device', function(done) {
var xml = fixture('device.xml');
var xml = h.fixture('device.xml');
test.domain.detachDevice(xml, function(err, result) {
expect(err).to.exist;

Expand All @@ -247,7 +256,7 @@ describe('Domain', function() {
});

it('should update a device', function(done) {
var xml = fixture('device_update.xml');
var xml = h.fixture('device_update.xml');
var flags = [libvirt.VIR_DOMAIN_DEVICE_MODIFY_CONFIG];
test.domain.updateDevice(xml, flags, function(err, result) {
expect(err).to.exist;
Expand Down Expand Up @@ -358,7 +367,9 @@ describe('Domain', function() {
});

it('should take, lookup, revert and delete a domain snapshot', function(done) {
var xml = fixture('snapshot.xml');
if (semver.lt(test.version, '1.0.0')) { return done(); }

var xml = h.fixture('snapshot.xml');
test.domain.takeSnapshot(xml, [], function(err) {
expect(err).to.not.exist;

Expand Down Expand Up @@ -461,9 +472,9 @@ describe('Domain', function() {
});

it('should return the uuid', function(done) {
test.domain.getUUID(function(err, domain) {
test.domain.getUUID(function(err, uuid) {
expect(err).to.not.exist;
expect(domain).to.equal('6695eb01-f6a4-8304-79aa-97f2502e193f');
expect(uuid).to.exist;
done();
});
});
Expand Down Expand Up @@ -645,6 +656,8 @@ describe('Domain', function() {
});

it('should return whether the domain has a managed save image', function(done) {
if (semver.lt(test.version, '1.0.0')) { return done(); }

test.domain.hasManagedSaveImage(function(err, result) {
expect(err).to.not.exist;
expect(result).to.be.false;
Expand Down Expand Up @@ -739,6 +752,8 @@ describe('Domain', function() {
});

it('should show if the domain has a current snapshot', function(done) {
if (semver.lt(test.version, '1.0.0')) { return done(); }

test.domain.hasCurrentSnapshot(function(err, res) {
expect(err).to.not.exist;
expect(res).to.be.false;
Expand All @@ -747,7 +762,9 @@ describe('Domain', function() {
});

it('should return information about the current domain snapshot', function(done) {
var xml = fixture('snapshot.xml');
if (semver.lt(test.version, '1.0.0')) { return done(); }

var xml = h.fixture('snapshot.xml');
test.domain.takeSnapshot(xml, [], function(err) {
expect(err).to.not.exist;

Expand Down Expand Up @@ -783,7 +800,9 @@ describe('Domain', function() {
});

it('should return all the domain snapshots', function(done) {
var xml = fixture('snapshot.xml');
if (semver.lt(test.version, '1.0.0')) { return done(); }

var xml = h.fixture('snapshot.xml');
test.domain.takeSnapshot(xml, [], function(err) {
expect(err).to.not.exist;

Expand Down
17 changes: 12 additions & 5 deletions test/hypervisor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
var libvirt = require('../lib'),
Hypervisor = libvirt.Hypervisor,
SegfaultHandler = require('segfault-handler'),
fixture = require('./lib/helper').fixture,
h = require('./lib/helper'),
semver = require('semver'),
expect = require('chai').expect;

var test = {};
describe('Hypervisor', function() {
before(function() {
SegfaultHandler.registerHandler();
return h.getLibVirtVersion()
.then(function(version) {
test.version = version;
});
});

describe('construction', function() {
Expand Down Expand Up @@ -193,9 +198,11 @@ describe('Hypervisor', function() {
});

it('should compute the most feature-rich CPU', function(done) {
var cpu1 = fixture('cpu1.xml');
var cpu2 = fixture('cpu2.xml');
var computed_cpu = fixture('match_bt_cpu1_and_cpu2.xml');
if (semver.lt(test.version, '1.0.0')) { return done(); }

var cpu1 = h.fixture('cpu1.xml');
var cpu2 = h.fixture('cpu2.xml');
var computed_cpu = h.fixture('match_bt_cpu1_and_cpu2.xml');
var xmlCPUs = [cpu1, cpu2];

test.hypervisor.getBaselineCPU(xmlCPUs, function(err, cpu) {
Expand All @@ -206,7 +213,7 @@ describe('Hypervisor', function() {
});

it('should compare given cpu description with host CPU', function(done) {
var cpu = fixture('cpu1.xml');
var cpu = h.fixture('cpu1.xml');

// NOTE: not supported by test driver
test.hypervisor.compareCPU(cpu, function(err, result) {
Expand Down
14 changes: 12 additions & 2 deletions test/lib/helper.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
'use strict';

var fs = require('fs');
var Promise = require('bluebird'),
fs = require('fs'),
cp = require('child_process');

module.exports = {
'fixture': function(file) {
fixture: function(file) {
var fixture = fs.readFileSync(__dirname + '/../fixtures/' + file, 'utf8');
return fixture;
},
getLibVirtVersion: function() {
return new Promise(function(resolve, reject) {
cp.exec('pkg-config --modversion libvirt', function(err, stdout, stderr) {
if (!!err) return reject(err);
resolve(stdout.trim());
});
});
}
};

0 comments on commit d035f6b

Please sign in to comment.