Class: Navo::Sandbox

Inherits:
Object
  • Object
show all
Defined in:
lib/navo/sandbox.rb

Overview

Manages the creation and maintenance of the test suite sandbox.

The sandbox is just a directory that contains the files and configuration needed to run a test within the suite’s container. A temporary directory on the host is maintained

Instance Method Summary collapse

Constructor Details

#initialize(suite:) ⇒ Sandbox

Returns a new instance of Sandbox.



12
13
14
# File 'lib/navo/sandbox.rb', line 12

def initialize(suite:)
  @suite = suite
end

Instance Method Details

#update_chef_configObject



16
17
18
19
20
# File 'lib/navo/sandbox.rb', line 16

def update_chef_config
  install_cookbooks
  install_chef_directories
  install_chef_config
end

#update_test_configObject



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
55
56
57
# File 'lib/navo/sandbox.rb', line 22

def update_test_config
  test_files_dir = File.join(@suite.repo_root, %w[test integration])
  suite_dir = File.join(test_files_dir, @suite.name)

  # serverspec, bats, etc.
  frameworks = Pathname.new(suite_dir).children
                                      .select(&:directory?)
                                      .map(&:basename)
                                      .map(&:to_s)

  suites_directory = File.join(@suite.busser_directory, 'suites')
  @suite.exec!(%w[mkdir -p] + [suites_directory])

  frameworks.each do |framework|
    host_framework_dir = File.join(suite_dir, framework)
    container_framework_dir = File.join(suites_directory, framework)

    @suite.exec!(%w[rm -rf] + [container_framework_dir])

    # In order to work with Busser, we need to copy the helper files into
    # the same directory as the suite's spec files. This avoids issues with
    # symlinks not matching up due to differences in directory structure
    # between host and container (test-kitchen does the same thing).
    helpers_directory = File.join(test_files_dir, 'helpers', framework)
    if File.directory?(helpers_directory)
      puts "Transferring #{framework} test suite helpers..."
      @suite.copy(from: File.join(helpers_directory, '.'),
                  to: container_framework_dir)
    end

    puts "Transferring #{framework} tests..."
    @suite.copy(from: File.join(host_framework_dir, '.'),
                to: container_framework_dir)
  end

end