-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(CAT-372) - Add tests for vagrant provision
- Loading branch information
1 parent
2b89d5a
commit 3fc3502
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |