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 15, 2024
1 parent 2b89d5a commit e96e9ef
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions spec/tasks/vagrant_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require 'json'
require 'rspec'

RSpec.shared_context('with tmpdir') do
let(:tmpdir) { @tmpdir } # rubocop:disable RSpec/InstanceVariable

around(:each) do |example|
Dir.mktmpdir('rspec-provision_test') do |t|
@tmpdir = t
example.run
end
end
end

describe 'vagrant' do
before(:each) do
# Stub $stdin.read to return a predefined JSON string
allow($stdin).to receive(:read).and_return({
platform: 'generic/debian10',
action: 'provision',
vars: 'role: worker1',
inventory: './spec/fixtures/litmus_inventory.yaml',
enable_synced_folder: 'true',
provider: 'virtualbox',
hyperv_vswitch: 'hyperv_vswitch',
hyperv_smb_username: 'hyperv_smb_username'
}.to_json)
# Load the task file after stubbing $stdin, as the task file reads from $stdin on load
require_relative '../../tasks/vagrant'
let(:inventory_dir) { "#{tmpdir}/spec/fixtures" }
let(:inventory_file) { "#{inventory_dir}/litmus_inventory.yaml" }

Check failure on line 32 in spec/tasks/vagrant_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)

Layout/TrailingWhitespace: Trailing whitespace detected. (https://rubystyle.guide#no-trailing-whitespace)

Check failure on line 32 in spec/tasks/vagrant_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

Layout/TrailingWhitespace: Trailing whitespace detected. (https://rubystyle.guide#no-trailing-whitespace)
include_context('with tmpdir')
end

it 'provisions a new vagrant box when action is provision' do
result = provision(platform, inventory_file, enable_synced_folder, provider, cpus, memory, hyperv_vswitch, hyperv_smb_username, hyperv_smb_password, box_url, password, vars)
expect(result[:status]).to eq('ok')
expect(result[:node_name]).not_to be_nil
expect(result[:node]['facts']['provisioner']).to eq('vagrant')
expect(result[:node]['facts']['platform']).to eq(platform)
expect(result[:node]['vars']).to eq(JSON.parse(vars))
end
end

0 comments on commit e96e9ef

Please sign in to comment.