File: unit_context.rb

package info (click to toggle)
vagrant-libvirt 0.12.2-4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,756 kB
  • sloc: ruby: 12,865; xml: 2,465; sh: 373; javascript: 235; makefile: 13
file content (54 lines) | stat: -rw-r--r-- 1,480 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# frozen_string_literal: true

require_relative '../spec_helper'

shared_context 'unit' do
  include_context 'vagrant-unit'

  let(:vagrantfile_providerconfig) { '' }
  let(:vagrantfile) do
    <<-EOF
    Vagrant.configure('2') do |config|
      config.vm.box = "vagrant-libvirt/test"
      config.vm.define :test
      config.vm.provider :libvirt do |libvirt|
        #{vagrantfile_providerconfig}
      end
    end
    EOF
  end
  let(:test_env) do
    test_env = isolated_environment
    test_env.vagrantfile vagrantfile
    test_env
  end
  let(:iso_env)          { test_env.create_vagrant_env ui_class: Vagrant::UI::Basic }
  let(:machine)          { iso_env.machine(:test, :libvirt) }
  let(:ui)               { Vagrant::UI::Silent.new }
  let(:env)              { { env: iso_env, machine: machine, ui: ui, root_path: '/rootpath' } }

  # Mock the communicator to prevent SSH commands for being executed.
  let(:communicator)     { double('communicator') }
  let(:app)              { ->(env) {} }

  before (:each) do
    allow(machine).to receive(:communicate).and_return(communicator)
    allow(machine).to receive(:ui).and_return(ui)
  end

  around do |example|
    Dir.mktmpdir do |tmpdir|
      original_home = ENV['HOME']

      begin
        virtual_home = File.expand_path(File.join(tmpdir, 'home'))
        Dir.mkdir(virtual_home)
        ENV['HOME'] = virtual_home

        example.run
      ensure
        ENV['HOME'] = original_home
      end
    end
  end
end