Skip to content

Commit

Permalink
add spec
Browse files Browse the repository at this point in the history
  • Loading branch information
hariszaf committed Aug 11, 2024
1 parent 48d9616 commit ca72c63
Show file tree
Hide file tree
Showing 122 changed files with 11,335 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/_layouts/about.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
layout: default
---

{{ content }}
53 changes: 53 additions & 0 deletions docs/_layouts/default.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
layout: table_wrappers
---

<!DOCTYPE html>

<html lang="{{ site.lang | default: 'en-US' }}">
{% assign version = page.version | default: 'latest' %}
{% include nav.html pages=site.pages version=version %}
{% include head.html %}

<script src="https://polyfill.io/v3/polyfill.js?features=es6">
</script>

<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>

<body>
<a class="skip-to-main" href="#main-content">Skip to main content</a>
{% include icons/icons.html %}
{% include components/sidebar.html %}
<div class="main" id="top">
{% include components/header.html %}
<div class="main-content-wrap">
{% include components/breadcrumbs.html %}
<div id="main-content" class="main-content">
<main>
{% if site.heading_anchors != false %}
{% include vendor/anchor_headings.html html=content beforeHeading="true" anchorBody="<svg viewBox=\"0 0 16
16\" aria-hidden=\"true\">
<use xlink:href=\"#svg-link\"></use>
</svg>" anchorClass="anchor-heading" anchorAttrs="aria-labelledby=\"%html_id%\"" %}
{% else %}
{{ content }}
{% endif %}

{% if page.has_children == true and page.has_toc != false %}
{% include components/children_nav.html %}
{% endif %}
</main>
{% include components/footer.html %}
</div>
</div>
{% if site.search_enabled != false %}
{% include components/search_footer.html %}
{% endif %}
</div>

{% if site.mermaid %}
{% include components/mermaid.html %}
{% endif %}
</body>

</html>
5 changes: 5 additions & 0 deletions docs/_layouts/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
layout: default
---

{{ content }}
34 changes: 34 additions & 0 deletions docs/_layouts/minimal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
layout: table_wrappers
---

<!DOCTYPE html>

<html lang="{{ site.lang | default: 'en-US' }}">
{% include head.html %}
<body>
<a class="skip-to-main" href="#main-content">Skip to main content</a>
{% include icons/icons.html %}
<div class="main-content-wrap" id="top">
{% include components/breadcrumbs.html %}
<div id="main-content" class="main-content" role="main">
{% if site.heading_anchors != false %}
{% include vendor/anchor_headings.html html=content beforeHeading="true" anchorBody="<svg viewBox=\"0 0 16 16\" aria-hidden=\"true\"><use xlink:href=\"#svg-link\"></use></svg>" anchorClass="anchor-heading" anchorAttrs="aria-labelledby=\"%html_id%\"" %}
{% else %}
{{ content }}
{% endif %}

{% if page.has_children == true and page.has_toc != false %}
{% include components/children_nav.html %}
{% endif %}

{% include components/footer.html %}

</div>
</div>

{% if site.mermaid %}
{% include components/mermaid.html %}
{% endif %}
</body>
</html>
5 changes: 5 additions & 0 deletions docs/_layouts/page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
layout: default
---

{{ content }}
5 changes: 5 additions & 0 deletions docs/_layouts/post.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
layout: default
---

{{ content }}
7 changes: 7 additions & 0 deletions docs/_layouts/table_wrappers.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
layout: vendor/compress
---

{% assign content_ = content | replace: '<table', '<div class="table-wrapper"><table' %}
{% assign content_ = content_ | replace: '</table>', '</table></div>' %}
{{ content_ }}
29 changes: 29 additions & 0 deletions spec/acceptance/additional_storage_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

require_relative '../spec_helper'

describe 'additional storage configured', acceptance: true do
include_context 'libvirt_acceptance'

before do
environment.skeleton('additional_storage')
end

after do
assert_execute('vagrant', 'destroy', '--force')
end

it 'should succeed' do
status('Test: machine is created successfully')
result = environment.execute('vagrant', 'up')
expect(result).to exit_with(0)

status('Test: additional storage configured')
expect(result.stdout).to match(/\(vda\).*work_default.img/)
expect(result.stdout).to match(/\(vdb\).*work_default-vdb\.qcow2/)

status('Test: reload handles additional storage correctly')
result = environment.execute('vagrant', 'reload')
expect(result).to exit_with(0)
end
end
41 changes: 41 additions & 0 deletions spec/acceptance/networking_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

require_relative '../spec_helper'

describe 'package domain', acceptance: true do
include_context 'libvirt_acceptance'

before(:all) do
expect(Vagrant::Util::Which.which('virsh')).to be_truthy,
'networking tests require virsh, please install'
expect(system('virsh --connect=qemu:///system uri >/dev/null')).to be_truthy,
'network tests require access to qemu:///system context, please ensure test user has correct permissions'
end

after(:each) do
assert_execute('vagrant', 'destroy', '--force')
end

before do
environment.skeleton('network_no_autostart')
end

context 'when host is rebooted' do
before do
result = environment.execute('vagrant', 'up')
expect(result).to exit_with(0)

result = environment.execute('vagrant', 'halt')
expect(result).to exit_with(0)

result = environment.execute('virsh', '--connect=qemu:///system', 'net-destroy', 'vagrant-libvirt-test')
expect(result).to exit_with(0)
end

it 'should start networking on restart' do
status('Test: machine restarts networking')
result = environment.execute('vagrant', 'up')
expect(result).to exit_with(0)
end
end
end
90 changes: 90 additions & 0 deletions spec/acceptance/package_domain_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# frozen_string_literal: true

require_relative '../spec_helper'

describe 'package domain', acceptance: true do
include_context 'libvirt_acceptance'

before(:all) do
expect(Vagrant::Util::Which.which('virt-sysprep')).to be_truthy,
'packaging tests require virt-sysprep, please install'
expect(Vagrant::Util::Which.which('virt-sparsify')).to be_truthy,
'packaging tests require virt-sparsify, please install'

result = (File.exist?('C:\\') ? `dir /-C #{Dir.tmpdir}` : `df #{Dir.tmpdir}`).split("\n").last
expect(result.split[3].to_i).to be > 6 * 1024 * 1024,
"packaging tests require more than 6GiB of space under #{Dir.tmpdir}"
end

after(:each) do
assert_execute('vagrant', 'destroy', '--force')
end

let(:testbox_envvars) { { VAGRANT_VAGRANTFILE: 'Vagrantfile.testbox' } }

context 'simple' do
before do
environment.skeleton('package_simple')
end

after do
result = environment.execute('vagrant', 'destroy', '--force', extra_env: testbox_envvars)
expect(result).to exit_with(0)

assert_execute('vagrant', 'box', 'remove', '--force', 'test-package-simple-domain')
end

it 'should succeed' do
status('Test: machine is created successfully')
expect(environment.execute('vagrant', 'up')).to exit_with(0)

status('Test: package machine successfully')
expect(environment.execute('vagrant', 'package')).to exit_with(0)

status('Test: add packaged box')
expect(environment.execute(
'vagrant', 'box', 'add', '--force', '--name', 'test-package-simple-domain', 'package.box'
)).to exit_with(0)

status('Test: machine from packaged box is created successfully')
result = environment.execute('vagrant', 'up', extra_env: testbox_envvars)
expect(result).to exit_with(0)
expect(result.stdout).to match(/test-package-simple-domain/)
end
end

context 'complex' do
before do
environment.skeleton('package_complex')
extra_env.merge!(
{
VAGRANT_LIBVIRT_VIRT_SYSPREP_OPERATIONS: 'defaults,-ssh-userdir,customize',
VAGRANT_LIBVIRT_VIRT_SYSPREP_OPTIONS: '--run $(pwd)/scripts/sysprep.sh',
}
)
end

after do
expect(environment.execute('vagrant', 'destroy', '--force', extra_env: testbox_envvars)).to exit_with(0)
assert_execute('vagrant', 'box', 'remove', '--force', 'test-package-complex-domain')
end

it 'should succeed' do
status('Test: machine is created successfully')
expect(environment.execute('vagrant', 'up')).to exit_with(0)

status('Test: package machine successfully')
expect(environment.execute('vagrant', 'package')).to exit_with(0)

status('Test: add packaged box')
expect(environment.execute(
'vagrant', 'box', 'add', '--force', '--name', 'test-package-complex-domain', 'package.box'
)).to exit_with(0)

status('Test: machine from packaged box is created successfully')
result = environment.execute('vagrant', 'up', extra_env: testbox_envvars)
expect(result).to exit_with(0)
expect(result.stdout).to match(/test-package-complex-domain/)
end
end
end
54 changes: 54 additions & 0 deletions spec/acceptance/provider_settings_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# frozen_string_literal: true

require_relative '../spec_helper'

describe 'provider settings', acceptance: true do
include_context 'libvirt_acceptance'

after do
assert_execute('vagrant', 'destroy', '--force')
end

context 'with defaults' do
before do
environment.skeleton('default_settings')
end

it 'should succeed' do
status('Test: machine is created successfully')
result = environment.execute('vagrant', 'up')
expect(result).to exit_with(0)

status('Test: CPU matches default')
expect(result.stdout).to match(/Cpus:\s+1$/)

status('Test: memory matches default')
expect(result.stdout).to match(/Memory:\s+512M/)

status('Test: default prefix is used')
expect(result.stdout).to match(/Name:\s+work_default$/)
end
end

context 'with modified config' do
before do
environment.skeleton('adjusted_settings')
end

it 'should succeed' do
status('Test: machine is created successfully')
result = environment.execute('vagrant', 'up')
expect(result).to exit_with(0)

status('Test: CPUs are changed')
expect(result.stdout).to match(/Cpus:\s+2$/)

status('Test: memory is changed')
expect(result.stdout).to match(/Memory:\s+1000M$/)

status('Test: default prefix is changed')
expect(result.stdout).to match(/Name:\s+changed_default_prefixdefault$/)
expect(result.stdout).to match(/\(vda\).*changed_default_prefixdefault\.img/)
end
end
end
Loading

0 comments on commit ca72c63

Please sign in to comment.