From dc3bfecd288dce91251235c9b4cfd4cd5ad9a9a2 Mon Sep 17 00:00:00 2001 From: Mikker Gimenez-Peterson Date: Tue, 14 Jan 2020 09:39:49 -0800 Subject: [PATCH] Adding spec test to ensure that all the interfaces are the same, while doing so, fix the broken interfaces for delete on vmpooler and nonstandard pooler(they were passed 5 by service.rb but expected 4) --- lib/vmfloaty/abs.rb | 12 ++++++++ lib/vmfloaty/nonstandard_pooler.rb | 2 +- lib/vmfloaty/pooler.rb | 2 +- spec/vmfloaty/nonstandard_pooler_spec.rb | 4 +-- spec/vmfloaty/pooler_spec.rb | 4 +-- spec/vmfloaty/vmfloaty_services_spec.rb | 39 ++++++++++++++++++++++++ 6 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 spec/vmfloaty/vmfloaty_services_spec.rb diff --git a/lib/vmfloaty/abs.rb b/lib/vmfloaty/abs.rb index 1cd9dc1..6673eb3 100644 --- a/lib/vmfloaty/abs.rb +++ b/lib/vmfloaty/abs.rb @@ -290,4 +290,16 @@ class ABS res = conn.get "host/#{hostname}" JSON.parse(res.body) end + + def self.modify(_verbose, _url, _hostname, _token, _modify_hash) + raise NoMethodError, 'modify is not defined for ABS' + end + + def self.disk(_verbose, _url, _hostname, _token, _disk) + raise NoMethodError, 'disk is not defined for ABS' + end + + def self.revert(_verbose, _url, _hostname, _token, _snapshot_sha) + raise NoMethodError, 'revert is not defined for ABS' + end end diff --git a/lib/vmfloaty/nonstandard_pooler.rb b/lib/vmfloaty/nonstandard_pooler.rb index 89f6c64..90722c0 100644 --- a/lib/vmfloaty/nonstandard_pooler.rb +++ b/lib/vmfloaty/nonstandard_pooler.rb @@ -77,7 +77,7 @@ class NonstandardPooler raise ModifyError, 'Configured service type does not support snapshots' end - def self.delete(verbose, url, hosts, token) + def self.delete(verbose, url, hosts, token, _user) raise TokenError, 'Token provided was nil; Request cannot be made to delete VM' if token.nil? conn = Http.get_conn(verbose, url) diff --git a/lib/vmfloaty/pooler.rb b/lib/vmfloaty/pooler.rb index b8a492e..c85daf3 100644 --- a/lib/vmfloaty/pooler.rb +++ b/lib/vmfloaty/pooler.rb @@ -94,7 +94,7 @@ class Pooler res_body end - def self.delete(verbose, url, hosts, token) + def self.delete(verbose, url, hosts, token, _user) raise TokenError, 'Token provided was nil. Request cannot be made to delete vm' if token.nil? conn = Http.get_conn(verbose, url) diff --git a/spec/vmfloaty/nonstandard_pooler_spec.rb b/spec/vmfloaty/nonstandard_pooler_spec.rb index 911c96c..8bcfe3c 100644 --- a/spec/vmfloaty/nonstandard_pooler_spec.rb +++ b/spec/vmfloaty/nonstandard_pooler_spec.rb @@ -274,7 +274,7 @@ describe NonstandardPooler do .with(:headers => @auth_token_headers) .to_return(:status => 200, :body => @delete_response_success, :headers => {}) - request = NonstandardPooler.delete(false, @nspooler_url, 'sol11-7', 'token-value') + request = NonstandardPooler.delete(false, @nspooler_url, 'sol11-7', 'token-value', nil) expect(request['sol11-7']['ok']).to be true end @@ -283,7 +283,7 @@ describe NonstandardPooler do .with(:headers => @auth_token_headers) .to_return(:status => 401, :body => @delete_response_failure, :headers => {}) - request = NonstandardPooler.delete(false, @nspooler_url, 'fakehost', 'token-value') + request = NonstandardPooler.delete(false, @nspooler_url, 'fakehost', 'token-value', nil) expect(request['fakehost']['ok']).to be false end end diff --git a/spec/vmfloaty/pooler_spec.rb b/spec/vmfloaty/pooler_spec.rb index dffaf2f..6d7def0 100644 --- a/spec/vmfloaty/pooler_spec.rb +++ b/spec/vmfloaty/pooler_spec.rb @@ -119,11 +119,11 @@ describe Pooler do .with(:headers => { 'X-Auth-Token' => 'mytokenfile' }) .to_return(:status => 200, :body => @delete_response_body_success, :headers => {}) - expect(Pooler.delete(false, @vmpooler_url, ['fq6qlpjlsskycq6'], 'mytokenfile')).to eq @delete_response + expect(Pooler.delete(false, @vmpooler_url, ['fq6qlpjlsskycq6'], 'mytokenfile', nil)).to eq @delete_response end it 'raises a token error if no token provided' do - expect { Pooler.delete(false, @vmpooler_url, ['myfakehost'], nil) }.to raise_error(TokenError) + expect { Pooler.delete(false, @vmpooler_url, ['myfakehost'], nil, nil) }.to raise_error(TokenError) end end diff --git a/spec/vmfloaty/vmfloaty_services_spec.rb b/spec/vmfloaty/vmfloaty_services_spec.rb new file mode 100644 index 0000000..4fe50e9 --- /dev/null +++ b/spec/vmfloaty/vmfloaty_services_spec.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +# All of the interfaces for the different services must be the +# same, otherwise there will be errors when you change the caller +# for the services from services.rb. +# + +require_relative '../../lib/vmfloaty/pooler' +require_relative '../../lib/vmfloaty/abs' +require_relative '../../lib/vmfloaty/nonstandard_pooler' + +shared_examples 'a vmfloaty service' do + it { is_expected.to respond_to(:delete).with(5).arguments } + it { is_expected.to respond_to(:disk).with(5).arguments } + it { is_expected.to respond_to(:list).with(3).arguments } + it { is_expected.to respond_to(:list_active).with(4).arguments } + it { is_expected.to respond_to(:modify).with(5).arguments } + it { is_expected.to respond_to(:retrieve).with(6).arguments } + it { is_expected.to respond_to(:revert).with(5).arguments } + it { is_expected.to respond_to(:query).with(3).arguments } + it { is_expected.to respond_to(:snapshot).with(4).arguments } + it { is_expected.to respond_to(:status).with(2).arguments } + it { is_expected.to respond_to(:summary).with(2).arguments } +end + +describe Pooler do + subject { Pooler } + it_behaves_like 'a vmfloaty service' +end + +describe ABS do + subject { ABS } + it_behaves_like 'a vmfloaty service' +end + +describe NonstandardPooler do + subject { NonstandardPooler } + it_behaves_like 'a vmfloaty service' +end