2018-09-25 10:32:53 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-10-15 12:06:44 -04:00
|
|
|
require 'fast_spec_helper'
|
2018-09-25 10:32:53 -04:00
|
|
|
|
|
|
|
RSpec.describe Quality::KubernetesClient do
|
2018-10-15 12:06:44 -04:00
|
|
|
let(:namespace) { 'review-apps-ee' }
|
|
|
|
let(:release_name) { 'my-release' }
|
|
|
|
|
|
|
|
subject { described_class.new(namespace: namespace) }
|
2018-09-25 10:32:53 -04:00
|
|
|
|
|
|
|
describe '#cleanup' do
|
2018-10-15 12:06:44 -04:00
|
|
|
it 'raises an error if the Kubernetes command fails' do
|
|
|
|
expect(Gitlab::Popen).to receive(:popen_with_detail)
|
|
|
|
.with([%(kubectl --namespace "#{namespace}" delete ) \
|
|
|
|
'ingress,svc,pdb,hpa,deploy,statefulset,job,pod,secret,configmap,pvc,secret,clusterrole,clusterrolebinding,role,rolebinding,sa ' \
|
|
|
|
"--now -l release=\"#{release_name}\""])
|
|
|
|
.and_return(Gitlab::Popen::Result.new([], '', '', double(success?: false)))
|
|
|
|
|
|
|
|
expect { subject.cleanup(release_name: release_name) }.to raise_error(described_class::CommandFailedError)
|
|
|
|
end
|
|
|
|
|
2018-09-25 10:32:53 -04:00
|
|
|
it 'calls kubectl with the correct arguments' do
|
2018-10-15 12:06:44 -04:00
|
|
|
expect(Gitlab::Popen).to receive(:popen_with_detail)
|
|
|
|
.with([%(kubectl --namespace "#{namespace}" delete ) \
|
|
|
|
'ingress,svc,pdb,hpa,deploy,statefulset,job,pod,secret,configmap,pvc,secret,clusterrole,clusterrolebinding,role,rolebinding,sa ' \
|
|
|
|
"--now -l release=\"#{release_name}\""])
|
|
|
|
.and_return(Gitlab::Popen::Result.new([], '', '', double(success?: true)))
|
2018-09-25 10:32:53 -04:00
|
|
|
|
|
|
|
# We're not verifying the output here, just silencing it
|
2018-10-15 12:06:44 -04:00
|
|
|
expect { subject.cleanup(release_name: release_name) }.to output.to_stdout
|
2018-09-25 10:32:53 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|