Add tests on pool.spec and vif.spec

This commit is contained in:
Varchar38
2015-07-15 17:22:52 +02:00
parent da648e0a78
commit 47d2d09e50
2 changed files with 210 additions and 0 deletions

83
src/pool.spec.js Normal file
View File

@@ -0,0 +1,83 @@
/* eslint-env mocha */
// Doc: https://github.com/moll/js-must/blob/master/doc/API.md#must
import expect from 'must'
// ===================================================================
import {getConnection, getConfig, waitObjectState} from './util'
import eventToPromise from 'event-to-promise'
// ===================================================================
describe('pool', function () {
let xo
let poolId
let serverId
before(async function () {
this.timeout(10e3)
xo = await getConnection()
const config = await getConfig()
serverId = await xo.call('server.add', config.xenServer1).catch(() => {})
await eventToPromise(xo.objects, 'finish')
poolId = getOnePoolId()
})
// -------------------------------------------------------------------
after(async function () {
await xo.call('server.remove', {
id: serverId
})
})
// ------------------------------------------------------------------
function getAllPool () {
return xo.objects.indexes.type.pool
}
function getOnePoolId () {
const pools = getAllPool()
for (const id in pools) {
return id
}
}
// ===================================================================
describe('.set()', function () {
afterEach(async function () {
await xo.call('pool.set', {
id: poolId,
name_label: '',
name_description: ''
})
})
it('set pool parameters', async function () {
await xo.call('pool.set', {
id: poolId,
name_label: 'nameTest',
name_description: 'description'
})
await waitObjectState(xo, poolId, pool => {
expect(pool.name_label).to.be.equal('nameTest')
expect(pool.name_description).to.be.equal('description')
})
})
})
// ------------------------------------------------------------------
describe('.installPatch()', function () {
it('install a patch on the pool')
})
// -----------------------------------------------------------------
describe('handlePatchUpload()', function () {
it('')
})
})

127
src/vif.spec.js Normal file
View File

@@ -0,0 +1,127 @@
/* eslint-env mocha */
// Doc: https://github.com/moll/js-must/blob/master/doc/API.md#must
import expect from 'must'
// ===================================================================
import {getConnection, getConfig, waitObjectState, getVmXoTestPvId} from './util'
import eventToPromise from 'event-to-promise'
// ===================================================================
describe('vif', function () {
let xo
let serverId
let vmId
before(async function () {
this.timeout(10e3)
xo = await getConnection()
const config = await getConfig()
serverId = await xo.call('server.add', config.xenServer1).catch(() => {})
await eventToPromise(xo.objects, 'finish')
vmId = await getVmXoTestPvId(xo)
try {
await xo.call('vm.start', {id: vmId})
} catch (_) {}
})
// -------------------------------------------------------------------
after(async function () {
try {
await xo.call('vif.connect', {id: vmId})
} catch (_) {}
await xo.call('vm.stop', {id: vmId, force: true})
await xo.call('server.remove', {
id: serverId
})
})
// -------------------------------------------------------------------
async function getVifId () {
const vm = await xo.getOrWaitObject(vmId)
return vm.VIFs[0]
}
// ===================================================================
describe('.delete()', function () {
it('deletes a VIF')
it('can not delete a VIF if it is not disconnected')
})
// ----------------------------------------------------------------
describe('.disconnect()', function () {
let vifId
beforeEach(async function () {
vifId = await getVifId()
})
afterEach(async function () {
await xo.call('vif.connect', {id: vifId})
})
it('disconnects a VIF', async function () {
await xo.call('vif.disconnect', {id: vifId})
await waitObjectState(xo, vifId, vif => {
expect(vif.attached).to.be.false()
})
})
it('can not disconnect a VIF if its VM is shutdowmed', async function () {
this.timeout(10e3)
await xo.call('vm.stop', {id: vmId})
await xo.call('vif.disconnect', {
id: vifId
}).then(
function () {
throw new Error('disconnect() should have thrown')
},
function (error) {
expect(error.message).to.be.equal('unknown error from the peer')
}
)
await xo.call('vm.start', {id: vmId})
})
})
// ----------------------------------------------------------------
describe('.connect()', function () {
let vifId
beforeEach(async function () {
vifId = await getVifId()
await xo.call('vif.disconnect', {id: vifId})
})
it('connects a VIF', async function () {
await xo.call('vif.connect', {id: vifId})
await waitObjectState(xo, vifId, vif => {
expect(vif.attached).to.be.true()
})
})
it('can not connect a VIF if its VM is shutdowmed', async function () {
this.timeout(10e3)
await xo.call('vm.stop', {id: vmId})
await xo.call('vif.connect', {
id: vifId
}).then(
function () {
throw new Error('connect() should have thrown')
},
function (error) {
expect(error.message).to.be.equal('unknown error from the peer')
}
)
await xo.call('vm.start', {id: vmId})
})
})
})