Skip to content

Commit

Permalink
Convert File mocks from expect to allow
Browse files Browse the repository at this point in the history
  • Loading branch information
diegotoral committed Jun 14, 2023
1 parent eefbad7 commit 2f70602
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions spec/k8s/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

subject { described_class }
context 'from KUBE_CA/KUBE_SERVER/KUBE_TOKEN variables' do

let(:server) { "localhost" }
let(:env) { { 'KUBE_TOKEN' => token, 'KUBE_CA' => ca, 'KUBE_SERVER' => server } }

Expand Down Expand Up @@ -125,18 +124,20 @@

context 'from default file locations' do
before do
stub_const("ENV", {}) # ensure ENV['KUBECONFIG'] is not used
expect(File).to receive(:read).and_call_original
expect(File).to receive(:exist?).and_call_original
expect(File).to receive(:readable?).and_call_original
expect(File).to receive(:exist?).with(default_kubeconfig_path).and_return(false)
expect(File).to receive(:exist?).with('/etc/kubernetes/admin.conf').and_return(false)
expect(File).to receive(:exist?).with('/etc/kubernetes/kubelet.conf').and_return(true)
expect(File).to receive(:readable?).with('/etc/kubernetes/kubelet.conf').and_return(true)
stub_const("ENV", { 'KUBECONFIG' => nil }) # ensure ENV['KUBECONFIG'] is not used

allow(File).to receive(:read).and_call_original
allow(File).to receive(:exist?).and_call_original
allow(File).to receive(:readable?).and_call_original

allow(File).to receive(:exist?).with(default_kubeconfig_path).and_return(false)
allow(File).to receive(:exist?).with('/etc/kubernetes/admin.conf').and_return(false)
allow(File).to receive(:exist?).with('/etc/kubernetes/kubelet.conf').and_return(true)
allow(File).to receive(:readable?).with('/etc/kubernetes/kubelet.conf').and_return(true)
end

it 'loads a file if found' do
expect(File).to receive(:read).with('/etc/kubernetes/kubelet.conf').and_return(kubeconfig)
allow(File).to receive(:read).with('/etc/kubernetes/kubelet.conf').and_return(kubeconfig)
expect(subject.autoconfig).to be_a K8s::Client
end
end
Expand Down

0 comments on commit 2f70602

Please sign in to comment.