Skip to content

Commit

Permalink
(CAT-372) - Add tests for vagrant provision
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanbreen28 committed May 16, 2024
1 parent 2b89d5a commit 3fc3502
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions spec/tasks/vagrant_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require 'json'
require 'rspec'
require 'spec_helper'
require 'net/ssh'

describe 'vagrant' do
let(:provider) { 'virtualbox' }
let(:platform) { 'generic/debian10' }

before(:each) do
# Stub $stdin.read to return a predefined JSON string
allow($stdin).to receive(:read).and_return({
platform: platform,
action: 'provision',
vars: 'role: worker1',
inventory: Dir.pwd.to_s,
enable_synced_folder: 'true',
provider: provider,
hyperv_vswitch: 'hyperv_vswitch',
hyperv_smb_username: 'hyperv_smb_username'
}.to_json)
allow(Open3).to receive(:capture3).with(%r{vagrant up --provider #{provider}}, any_args).and_return(['', '', 0]).once
allow(File).to receive(:read).with(%r{#{Dir.pwd}/.vagrant}).and_return('some_unique_id')
allow(Open3).to receive(:capture3).with(%r{vagrant ssh-config}, any_args).and_return(['', '', 0]).once
allow(Net::SSH).to receive(:start).and_return(true)
require_relative '../../tasks/vagrant'
end

it 'provisions a new vagrant box when action is provision' do
expect { vagrant }.to output(%r{"status":"ok"}).to_stdout
expect { vagrant }.to output(%r{"platform":"generic/debian10"}).to_stdout
expect { vagrant }.to output(%r{"role":"worker1"}).to_stdout
end
end

0 comments on commit 3fc3502

Please sign in to comment.