require 'spec_helper' module Falcore describe Node::Base do subject do Node::Base.new( 'displayName' => 'jenkins.example.com', 'idle' => true, ) end describe '#initialize' do let(:data) { { 'this' => 'that' } } subject { Node::Base.new(data) } it 'saves the data to @data' do expect(subject.instance_variable_get(:@data)).to eq(data) end it 'dups the data' do expect(data).to receive(:dup).once subject end end its(:id) { should eq('jenkins.jenkins-example-com') } its(:display_name) { should eq('jenkins.example.com') } describe '#idle?' do context 'when @data.idle is true' do subject { Node::Base.new('idle' => true) } its(:idle?) { should be_true } end context 'when @data.idle is false' do subject { Node::Base.new('idle' => false) } its(:idle?) { should be_false } end context 'when @data.idle is nil' do subject { Node::Base.new('idle' => nil) } its(:idle?) { should be_false } end end describe '#executors' do context 'when the value is nil' do subject { Node::Base.new } its(:executors) { should eq(0) } end context 'when the value is a string' do subject { Node::Base.new('numExecutors' => '5') } its(:executors) { should eq(5) } end context 'when the value is an integer' do subject { Node::Base.new('numExecutors' => 10) } its(:executors) { should eq(10) } end end describe '#offline?' do context 'when @data.offline is true' do subject { Node::Base.new('offline' => true) } its(:offline?) { should be_true } end context 'when @data.offline is false' do subject { Node::Base.new('offline' => false) } its(:offline?) { should be_false } end context 'when @data.offline is nil' do subject { Node::Base.new('offline' => nil) } its(:offline?) { should be_false } end end describe '#temporarily_offline?' do context 'when @data.temporarily_offline is true' do subject { Node::Base.new('temporarilyOffline' => true) } its(:temporarily_offline?) { should be_true } end context 'when @data.temporarily_offline is false' do subject { Node::Base.new('temporarilyOffline' => false) } its(:temporarily_offline?) { should be_false } end context 'when @data.temporarily_offline is nil' do subject { Node::Base.new('temporarilyOffline' => nil) } its(:temporarily_offline?) { should be_false } end end describe '#response_time' do context 'when the value is nil' do subject { Node::Base.new } its(:response_time) { should eq(0.0) } end context 'when the value is a string' do subject do Node::Base.new( 'monitorData' => { 'hudson.node_monitors.ResponseTimeMonitor' => { 'average' => '0.332' } } ) end its(:response_time) { should eq(0.332) } end context 'when the value is an integer' do subject do Node::Base.new( 'monitorData' => { 'hudson.node_monitors.ResponseTimeMonitor' => { 'average' => 0.194 } } ) end its(:response_time) { should eq(0.194) } end end describe '#temporary_space' do context 'when the value is nil' do subject { Node::Base.new } its(:temporary_space) { should eq(0) } end context 'when the value is a string' do subject do Node::Base.new( 'monitorData' => { 'hudson.node_monitors.TemporarySpaceMonitor' => { 'size' => '16421466112' } } ) end its(:temporary_space) { should eq(16421466112) } end context 'when the value is an integer' do subject do Node::Base.new( 'monitorData' => { 'hudson.node_monitors.TemporarySpaceMonitor' => { 'size' => 4421461112 } } ) end its(:temporary_space) { should eq(4421461112) } end end describe '#disk_space' do context 'when the value is nil' do subject { Node::Base.new } its(:disk_space) { should eq(0) } end context 'when the value is a string' do subject do Node::Base.new( 'monitorData' => { 'hudson.node_monitors.DiskSpaceMonitor' => { 'size' => '26424266182' } } ) end its(:disk_space) { should eq(26424266182) } end context 'when the value is an integer' do subject do Node::Base.new( 'monitorData' => { 'hudson.node_monitors.DiskSpaceMonitor' => { 'size' => 1490284902 } } ) end its(:disk_space) { should eq(1490284902) } end end describe '#free_memory' do context 'when the value is nil' do subject { Node::Base.new } its(:free_memory) { should eq(0) } end context 'when the value is a string' do subject do Node::Base.new( 'monitorData' => { 'hudson.node_monitors.SwapSpaceMonitor' => { 'availablePhysicalMemory' => '3719038410' } } ) end its(:free_memory) { should eq(3719038410) } end context 'when the value is an integer' do subject do Node::Base.new( 'monitorData' => { 'hudson.node_monitors.SwapSpaceMonitor' => { 'availablePhysicalMemory' => 193042 } } ) end its(:free_memory) { should eq(193042) } end end describe '#total_memory' do context 'when the value is nil' do subject { Node::Base.new } its(:total_memory) { should eq(0) } end context 'when the value is a string' do subject do Node::Base.new( 'monitorData' => { 'hudson.node_monitors.SwapSpaceMonitor' => { 'totalPhysicalMemory' => '28904283' } } ) end its(:total_memory) { should eq(28904283) } end context 'when the value is an integer' do subject do Node::Base.new( 'monitorData' => { 'hudson.node_monitors.SwapSpaceMonitor' => { 'totalPhysicalMemory' => 89048092 } } ) end its(:total_memory) { should eq(89048092) } end end describe '#free_swap' do context 'when the value is nil' do subject { Node::Base.new } its(:free_swap) { should eq(0) } end context 'when the value is a string' do subject do Node::Base.new( 'monitorData' => { 'hudson.node_monitors.SwapSpaceMonitor' => { 'availableSwapSpace' => '319048091' } } ) end its(:free_swap) { should eq(319048091) } end context 'when the value is an integer' do subject do Node::Base.new( 'monitorData' => { 'hudson.node_monitors.SwapSpaceMonitor' => { 'availableSwapSpace' => 83903890 } } ) end its(:free_swap) { should eq(83903890) } end end describe '#total_swap' do context 'when the value is nil' do subject { Node::Base.new } its(:total_swap) { should eq(0) } end context 'when the value is a string' do subject do Node::Base.new( 'monitorData' => { 'hudson.node_monitors.SwapSpaceMonitor' => { 'totalSwapSpace' => '319894031' } } ) end its(:total_swap) { should eq(319894031) } end context 'when the value is an integer' do subject do Node::Base.new( 'monitorData' => { 'hudson.node_monitors.SwapSpaceMonitor' => { 'totalSwapSpace' => 8390183190 } } ) end its(:total_swap) { should eq(8390183190) } end end end end