debian-mirror-gitlab/spec/lib/quality/kubernetes_client_spec.rb

34 lines
1.4 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2018-12-13 13:39:08 +05:30
require 'fast_spec_helper'
2018-12-05 23:21:45 +05:30
RSpec.describe Quality::KubernetesClient do
2018-12-13 13:39:08 +05:30
let(:namespace) { 'review-apps-ee' }
let(:release_name) { 'my-release' }
subject { described_class.new(namespace: namespace) }
2018-12-05 23:21:45 +05:30
describe '#cleanup' do
2018-12-13 13:39:08 +05:30
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-12-05 23:21:45 +05:30
it 'calls kubectl with the correct arguments' do
2018-12-13 13:39:08 +05:30
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-12-05 23:21:45 +05:30
# We're not verifying the output here, just silencing it
2018-12-13 13:39:08 +05:30
expect { subject.cleanup(release_name: release_name) }.to output.to_stdout
2018-12-05 23:21:45 +05:30
end
end
end