Class: Kitchen::Busser
- Inherits:
-
Object
- Object
- Kitchen::Busser
- Defined in:
- lib/kitchen/busser.rb
Overview
Command string generator to interface with Busser. The commands that are generated are safe to pass to an SSH command or as an unix command argument (escaped in single quotes).
Instance Method Summary collapse
-
#[](attr) ⇒ Object
Provides hash-like access to configuration keys.
-
#config_keys ⇒ Array
Returns an array of configuration keys.
-
#diagnose ⇒ Hash
Returns a Hash of configuration and other useful diagnostic information.
-
#initialize(suite_name, opts = {}) ⇒ Busser
constructor
Constructs a new Busser command generator, given a suite name.
-
#name ⇒ String
Returns the name of this busser, suitable for display in a CLI.
-
#run_cmd ⇒ String
Returns a command string which runs all Busser suite tests for the suite.
-
#setup_cmd ⇒ String
Returns a command string which installs Busser, and installs all required Busser plugins for the suite.
-
#sync_cmd ⇒ String
Returns a command string which transfers all suite test files to the instance.
Constructor Details
#initialize(suite_name, opts = {}) ⇒ Busser
Constructs a new Busser command generator, given a suite name.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/kitchen/busser.rb', line 41 def initialize(suite_name, opts = {}) (suite_name) kitchen_root = opts.fetch(:kitchen_root) { Dir.pwd } test_base_path = opts.fetch(:test_base_path, Kitchen::DEFAULT_TEST_DIR) @config = Hash.new @config[:kitchen_root] = kitchen_root @config[:test_base_path] = File.(test_base_path, kitchen_root) @config[:suite_name] = suite_name @config[:sudo] = opts.fetch(:sudo, true) @config[:ruby_bindir] = opts.fetch(:ruby_bindir, DEFAULT_RUBY_BINDIR) @config[:root_path] = opts.fetch(:root_path, DEFAULT_ROOT_PATH) @config[:version] = opts.fetch(:version, "busser") @config[:busser_bin] = opts.fetch(:busser_bin, File.join(@config[:root_path], "bin/busser")) end |
Instance Method Details
#[](attr) ⇒ Object
Provides hash-like access to configuration keys.
76 77 78 |
# File 'lib/kitchen/busser.rb', line 76 def [](attr) config[attr] end |
#config_keys ⇒ Array
Returns an array of configuration keys.
68 69 70 |
# File 'lib/kitchen/busser.rb', line 68 def config_keys config.keys end |
#diagnose ⇒ Hash
Returns a Hash of configuration and other useful diagnostic information.
83 84 85 86 87 |
# File 'lib/kitchen/busser.rb', line 83 def diagnose result = Hash.new config_keys.sort.each { |k| result[k] = config[k] } result end |
#name ⇒ String
Returns the name of this busser, suitable for display in a CLI.
61 62 63 |
# File 'lib/kitchen/busser.rb', line 61 def name config[:suite_name] end |
#run_cmd ⇒ String
Returns a command string which runs all Busser suite tests for the suite.
If no work needs to be performed, for example if there are no tests for
the given suite, then nil will be returned.
151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/kitchen/busser.rb', line 151 def run_cmd return if local_suite_files.empty? cmd = <<-CMD.gsub(/^ {8}/, "") #{busser_setup_env} #{sudo(config[:busser_bin])} test CMD Util.wrap_command(cmd) end |
#setup_cmd ⇒ String
Returns a command string which installs Busser, and installs all required Busser plugins for the suite.
If no work needs to be performed, for example if there are no tests for
the given suite, then nil will be returned.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/kitchen/busser.rb', line 97 def setup_cmd return if local_suite_files.empty? ruby = "#{config[:ruby_bindir]}/ruby" gem = sudo("#{config[:ruby_bindir]}/gem") busser = sudo(config[:busser_bin]) cmd = <<-CMD.gsub(/^ {8}/, "") #{busser_setup_env} gem_bindir=`#{ruby} -rrubygems -e "puts Gem.bindir"` if ! #{gem} list busser -i >/dev/null; then #{gem} install #{gem_install_args} fi #{sudo("${gem_bindir}")}/busser setup #{busser} plugin install #{plugins.join(" ")} CMD Util.wrap_command(cmd) end |
#sync_cmd ⇒ String
Returns a command string which transfers all suite test files to the instance.
If no work needs to be performed, for example if there are no tests for
the given suite, then nil will be returned.
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/kitchen/busser.rb', line 125 def sync_cmd return if local_suite_files.empty? cmd = <<-CMD.gsub(/^ {8}/, "") #{busser_setup_env} #{sudo(config[:busser_bin])} suite cleanup CMD local_suite_files.each do |f| cmd << stream_file(f, remote_file(f, config[:suite_name])).concat("\n") end helper_files.each do |f| cmd << stream_file(f, remote_file(f, "helpers")).concat("\n") end Util.wrap_command(cmd) end |