diff --git a/package.json b/package.json index 4d77ec7..5aab0d9 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/test/domain.test.js b/test/domain.test.js index dada55d..7f4117d 100644 --- a/test/domain.test.js +++ b/test/domain.test.js @@ -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() { @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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(); }); }); @@ -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; @@ -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; @@ -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; @@ -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; diff --git a/test/hypervisor.test.js b/test/hypervisor.test.js index 3cada36..7963a42 100644 --- a/test/hypervisor.test.js +++ b/test/hypervisor.test.js @@ -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() { @@ -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) { @@ -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) { diff --git a/test/lib/helper.js b/test/lib/helper.js index 59b01a7..2d8cea7 100644 --- a/test/lib/helper.js +++ b/test/lib/helper.js @@ -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()); + }); + }); } };