mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Migrate acceptance tests to rspec (#1513)
Move existing tests executed with the help of bats to use rspec directly combined with tags to filter them out from being executed by default. This allows for more complex assertions as well as easier debug as the code supports use of setting 'VAGRANT_SPEC_SKIP_CLEANUP' to prevent the tests from removing the temporary directory created for home and work directories. Extend a number of classes from vagrant-spec to override default behaviour to allow passing of additional environment variables for packaging tests, as well as supporting the skip cleanup. Given the use of after to perform the cleanup, need to vendor the vagrant-spec acceptance context in order to modify it easily.
This commit is contained in:
34
spec/acceptance/use_qemu_agent_for_connectivity_spec.rb
Normal file
34
spec/acceptance/use_qemu_agent_for_connectivity_spec.rb
Normal file
@@ -0,0 +1,34 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'use qemu agent to determine machine private address', acceptance: true do
|
||||
include_context 'libvirt_acceptance'
|
||||
|
||||
before do
|
||||
environment.skeleton('qemu_agent')
|
||||
end
|
||||
|
||||
after do
|
||||
assert_execute('vagrant', 'destroy', '--force')
|
||||
end
|
||||
|
||||
it 'should succeed' do
|
||||
status('Test: machine is created successfully')
|
||||
expect(environment.execute('vagrant', 'up')).to exit_with(0)
|
||||
|
||||
# extract SSH IP address emitted as it should be the private network since
|
||||
# the mgmt network has not been attached
|
||||
hostname = result.stdout.each_line.find { |line| line.include?('SSH address:') }
|
||||
expect(hostname).to_not be_nil
|
||||
ip_address = hostname.strip.split.last.split(':').first
|
||||
# default private network for vagrant-libvirt unless explicitly configured
|
||||
expect(IPAddr.new('172.28.128.0/255.255.255.0')).to include(IPAddr.new(ip_address))
|
||||
|
||||
# ssh'ing successfully means that the private network is accessible
|
||||
status('Test: machine private network is accessible')
|
||||
result = environment.execute('vagrant', 'ssh', '-c', 'echo "hello, world"')
|
||||
expect(result).to exit_with(0)
|
||||
expect(result.stdout).to match(/hello, world/)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user