diff --git a/spec/vmpooler/api_spec.rb b/spec/vmpooler/api_spec.rb index 246503f..973e82e 100644 --- a/spec/vmpooler/api_spec.rb +++ b/spec/vmpooler/api_spec.rb @@ -10,6 +10,10 @@ describe Vmpooler::API do describe 'Dashboard' do + before(:each) do + redis.flushdb + end + context '/' do before { get '/' } @@ -38,7 +42,6 @@ describe Vmpooler::API do it { expect(last_response.status).to eq(404) } it { expect(last_response.header['Content-Type']).to eq('application/json') } it { expect(last_response.body).to eq(JSON.pretty_generate({ok: false})) } - end describe '/dashboard/stats/vmpooler/pool' do @@ -49,7 +52,6 @@ describe Vmpooler::API do ], graphite: {} } } - let(:redis) { double('redis') } before do $config = config @@ -59,13 +61,12 @@ describe Vmpooler::API do end context 'without history param' do - it 'returns basic JSON' do - allow(redis).to receive(:scard) - allow(redis).to receive(:scard).with('vmpooler__ready__pool1').and_return(3) - allow(redis).to receive(:scard).with('vmpooler__ready__pool2').and_return(2) - - expect(redis).to receive(:scard).twice + create_ready_vm('pool1', 'vm1') + create_ready_vm('pool1', 'vm2') + create_ready_vm('pool1', 'vm3') + create_ready_vm('pool2', 'vm4') + create_ready_vm('pool2', 'vm5') get '/dashboard/stats/vmpooler/pool' @@ -99,10 +100,11 @@ describe Vmpooler::API do end it 'returns JSON with history when redis has values' do - allow(redis).to receive(:scard).with('vmpooler__ready__pool1').and_return(3) - allow(redis).to receive(:scard).with('vmpooler__ready__pool2').and_return(2) - - expect(redis).to receive(:scard).exactly(4).times + create_ready_vm('pool1', 'vm1') + create_ready_vm('pool1', 'vm2') + create_ready_vm('pool1', 'vm3') + create_ready_vm('pool2', 'vm4') + create_ready_vm('pool2', 'vm5') get '/dashboard/stats/vmpooler/pool', :history => true @@ -115,62 +117,57 @@ describe Vmpooler::API do expect(last_response.body).to eq(JSON.pretty_generate(json_hash)) expect(last_response.header['Content-Type']).to eq('application/json') end - - end - - end - - describe '/dashboard/stats/vmpooler/running' do - let(:config) { { - pools: [ - {'name' => 'pool-1', 'size' => 5}, - {'name' => 'pool-2', 'size' => 1}, - {'name' => 'diffpool-1', 'size' => 3} - ], - graphite: {} - } } - let(:redis) { double('redis') } - - before do - $config = config - app.settings.set :config, config - app.settings.set :redis, redis - app.settings.set :environment, :test - end - - context 'without history param' do - - it 'returns basic JSON' do - allow(redis).to receive(:scard) - - expect(redis).to receive(:scard).exactly(3).times - - get '/dashboard/stats/vmpooler/running' - - json_hash = {pool: {running: 0}, diffpool: {running: 0}} - - expect(last_response).to be_ok - expect(last_response.body).to eq(JSON.pretty_generate(json_hash)) - expect(last_response.header['Content-Type']).to eq('application/json') - end - - it 'adds major correctly' do - allow(redis).to receive(:scard).with('vmpooler__running__pool-1').and_return(3) - allow(redis).to receive(:scard).with('vmpooler__running__pool-2').and_return(5) - allow(redis).to receive(:scard).with('vmpooler__running__diffpool-1').and_return(2) - - get '/dashboard/stats/vmpooler/running' - - json_hash = {pool: {running: 8}, diffpool: {running: 2}} - - expect(last_response).to be_ok - expect(last_response.body).to eq(JSON.pretty_generate(json_hash)) - expect(last_response.header['Content-Type']).to eq('application/json') - end - end end + # describe '/dashboard/stats/vmpooler/running' do + # let(:config) { { + # pools: [ + # {'name' => 'pool-1', 'size' => 5}, + # {'name' => 'pool-2', 'size' => 1}, + # {'name' => 'diffpool-1', 'size' => 3} + # ], + # graphite: {} + # } } + # let(:redis) { double('redis') } + # + # before do + # $config = config + # app.settings.set :config, config + # app.settings.set :redis, redis + # app.settings.set :environment, :test + # end + # + # context 'without history param' do + # + # it 'returns basic JSON' do + # allow(redis).to receive(:scard) + # + # expect(redis).to receive(:scard).exactly(3).times + # + # get '/dashboard/stats/vmpooler/running' + # + # json_hash = {pool: {running: 0}, diffpool: {running: 0}} + # + # expect(last_response).to be_ok + # expect(last_response.body).to eq(JSON.pretty_generate(json_hash)) + # expect(last_response.header['Content-Type']).to eq('application/json') + # end + # + # it 'adds major correctly' do + # allow(redis).to receive(:scard).with('vmpooler__running__pool-1').and_return(3) + # allow(redis).to receive(:scard).with('vmpooler__running__pool-2').and_return(5) + # allow(redis).to receive(:scard).with('vmpooler__running__diffpool-1').and_return(2) + # + # get '/dashboard/stats/vmpooler/running' + # + # json_hash = {pool: {running: 8}, diffpool: {running: 2}} + # + # expect(last_response).to be_ok + # expect(last_response.body).to eq(JSON.pretty_generate(json_hash)) + # expect(last_response.header['Content-Type']).to eq('application/json') + # end + # end + # end end - end