From e5ac1bc629d5f39e3d667d86dc58ddbe34f669b4 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Tue, 14 Jan 2014 18:22:01 +0100 Subject: [PATCH] More tests. --- src/spec2.coffee | 16 ++++++++++------ src/spec2.spec.coffee | 21 ++++++++++++--------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/spec2.coffee b/src/spec2.coffee index 457593c94..50fa0cb2c 100644 --- a/src/spec2.coffee +++ b/src/spec2.coffee @@ -10,7 +10,7 @@ $isVMRunning = -> false $isHostRunning = -> - @genval.power_state is 'Running' + @val.power_state is 'Running' $isTaskLive = -> @genval.status is 'pending' or @genval.status is 'cancelling' @@ -60,6 +60,10 @@ module.exports = -> @val.ref = -> @genval.$ref @val.poolRef = -> @genval.$poolRefRef + # Helper to create multiple rules with the same definition. + rules = (rules, definition) => + @rule rule, definition for rule in rules + # An item is equivalent to a rule but one and only one instance of # this rule is created without any generator. @item xo: -> @@ -124,8 +128,7 @@ module.exports = -> VMs: $set { rule: 'VM' - # bind: -> @val.$container - if: $isVMRunning + bind: -> @val.$container } $running_hosts: $set { @@ -137,7 +140,7 @@ module.exports = -> $running_VMs: $set { rule: 'VM' bind: -> @genval.$poolRef - if: $isVMRunning + if: $isHostRunning } $VMs: $set { @@ -159,6 +162,7 @@ module.exports = -> controller: $val { rule: 'VM-controller' bind: -> @val.$container + val: -> @key } CPUs: -> @genval.cpu_info @@ -227,7 +231,7 @@ module.exports = -> } } - @rule VM: -> + rules ['VM', 'VM-controller', 'VM-template', 'VM-snapshot'], -> @val = { name_label: -> @genval.name_label @@ -294,7 +298,7 @@ module.exports = -> @genval.resident_on else # TODO: Handle local VMs. - @genval.$poolRefRef + @genval.$poolRef snapshots: -> @genval.snapshots diff --git a/src/spec2.spec.coffee b/src/spec2.spec.coffee index a0c530f32..8059013fd 100644 --- a/src/spec2.spec.coffee +++ b/src/spec2.spec.coffee @@ -79,10 +79,9 @@ describe 'spec2', -> $expect(pool.tags).to.have.members [] - console.log pool - # $expect(pool.SRs).to.have.members [ - # # TODO - # ] + $expect(pool.SRs).to.have.members [ + # TODO + ] $expect(pool.HA_enabled).to.be.false @@ -94,7 +93,9 @@ describe 'spec2', -> $expect(pool.master).to.equal 'OpaqueRef:bbc98f5e-1a17-2030-28af-0df2393f3145' $expect(pool.VMs).to.have.members [ - # TODO + 'OpaqueRef:d4fa8fba-ec86-5928-a1bb-dd78b6fb5944' + 'OpaqueRef:8491f148-3e78-9c74-ab98-84445c5f2861' + 'OpaqueRef:13b9ec24-04ea-ae04-78e6-6ec4b81a8deb' ] $expect(pool.$running_hosts).to.have.members [ @@ -128,7 +129,7 @@ describe 'spec2', -> it 'host', -> host = collection.get 'OpaqueRef:bbc98f5e-1a17-2030-28af-0df2393f3145' - #console.log host + #console.log host $expect(host).to.be.an 'object' @@ -142,7 +143,7 @@ describe 'spec2', -> $expect(host.address).to.equal '192.168.1.1' - #$expect(host.controller).to.equal '' # TODO + $expect(host.controller).to.equal 'OpaqueRef:719e4877-c7ad-68be-6b04-5750c8dcfeed' # Burk. $expect(host.CPUs).to.deep.equal { @@ -178,7 +179,8 @@ describe 'spec2', -> ] $expect(host.VMs).to.have.members [ - + 'OpaqueRef:fdaba312-c3a5-0190-b1a1-bf389567e620' + 'OpaqueRef:46fa4c52-5e93-6cf7-32e3-c51fb4ed106d' ] $expect(host.$PBDs).to.have.members [ @@ -199,7 +201,8 @@ describe 'spec2', -> ] $expect(host.$running_VMs).to.have.members [ - + 'OpaqueRef:fdaba312-c3a5-0190-b1a1-bf389567e620' + 'OpaqueRef:46fa4c52-5e93-6cf7-32e3-c51fb4ed106d' ] $expect(host.$vCPUs).to.equal 0