Commit 3eff73d5 authored by Alan (Maciej) Paruszewski's avatar Alan (Maciej) Paruszewski Committed by Jan Provaznik

Extract logic used for testing response to Kubeclient error

This change extracts logic used in tests related to Kubeclient errors to
shared examples to remove duplication in tests
parent bd2d7e45
...@@ -48,24 +48,7 @@ RSpec.describe NetworkPolicies::DeleteResourceService do ...@@ -48,24 +48,7 @@ RSpec.describe NetworkPolicies::DeleteResourceService do
end end
end end
context 'with Kubeclient::HttpError' do include_examples 'responds to Kubeclient::HttpError', :delete_network_policy
let(:request_url) { 'https://kubernetes.local' }
let(:response) { RestClient::Response.create('', {}, RestClient::Request.new(url: request_url, method: :get)) }
before do
allow(kubeclient).to receive(:delete_network_policy).and_raise(Kubeclient::HttpError.new(500, 'system failure', response))
end
it 'returns error response' do
expect(subject).to be_error
expect(subject.http_status).to eq(:bad_request)
expect(subject.message).not_to be_nil
end
it 'returns error message without request url' do
expect(subject.message).not_to include(request_url)
end
end
context 'with CiliumNetworkPolicy' do context 'with CiliumNetworkPolicy' do
let(:manifest) do let(:manifest) do
......
...@@ -93,24 +93,7 @@ RSpec.describe NetworkPolicies::DeployResourceService do ...@@ -93,24 +93,7 @@ RSpec.describe NetworkPolicies::DeployResourceService do
end end
end end
context 'with Kubeclient::HttpError' do include_examples 'responds to Kubeclient::HttpError', :create_network_policy
let(:request_url) { 'https://kubernetes.local' }
let(:response) { RestClient::Response.create('', {}, RestClient::Request.new(url: request_url, method: :get)) }
before do
allow(kubeclient).to receive(:create_network_policy).and_raise(Kubeclient::HttpError.new(500, 'system failure', response))
end
it 'returns error response' do
expect(subject).to be_error
expect(subject.http_status).to eq(:bad_request)
expect(subject.message).not_to be_nil
end
it 'returns error message without request url' do
expect(subject.message).not_to include(request_url)
end
end
context 'with cilium network policy' do context 'with cilium network policy' do
let(:manifest) do let(:manifest) do
......
...@@ -61,23 +61,6 @@ RSpec.describe NetworkPolicies::FindResourceService do ...@@ -61,23 +61,6 @@ RSpec.describe NetworkPolicies::FindResourceService do
end end
end end
context 'with Kubeclient::HttpError' do include_examples 'responds to Kubeclient::HttpError', :get_network_policy
let(:request_url) { 'https://kubernetes.local' }
let(:response) { RestClient::Response.create('', {}, RestClient::Request.new(url: request_url, method: :get)) }
before do
allow(kubeclient).to receive(:get_network_policy).and_raise(Kubeclient::HttpError.new(500, 'system failure', response))
end
it 'returns error response' do
expect(subject).to be_error
expect(subject.http_status).to eq(:bad_request)
expect(subject.message).not_to be_nil
end
it 'returns error message without request url' do
expect(subject.message).not_to include(request_url)
end
end
end end
end end
# frozen_string_literal: true
RSpec.shared_examples 'responds to Kubeclient::HttpError' do |kubeclient_method|
context 'with Kubeclient::HttpError' do
let(:request_url) { 'https://kubernetes.local' }
let(:response) { RestClient::Response.create('', {}, RestClient::Request.new(url: request_url, method: :get)) }
before do
allow(kubeclient).to receive(kubeclient_method).and_raise(Kubeclient::HttpError.new(500, 'system failure', response))
end
it 'returns error response', :aggregate_failures do
expect(subject).to be_error
expect(subject.http_status).to eq(:bad_request)
expect(subject.message).not_to be_nil
end
it 'returns error message without request url' do
expect(subject.message).not_to include(request_url)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment