beaker-testmode_switcher 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e5e98040bb38ccc30cecf1a0c3105dcd152b82e
4
- data.tar.gz: c6a864d09aec964392418110e6660402f2a37540
3
+ metadata.gz: c7ff5d01994fcc8fd23b932a148f2652929885a9
4
+ data.tar.gz: 1f09d49b242599f033255c7089837cf7a75fd19a
5
5
  SHA512:
6
- metadata.gz: ea53e552475d862693ff0a0b92cae19aea7cb235a4d290ba137d14ef0b6311f3d4003592db6cc8e333377a5b62ac388531399d7c1221b9ade06c5a3f1a4163f7
7
- data.tar.gz: 5fd3d099591b07fc46cdc27f3d6b0c511da666d79a4c49c2d2b170ed119fee39c9156e0b7bdbb9f54d16cafbf7589d8143dc1721f9f07bf6577bc7d9e5da1fca
6
+ metadata.gz: 29e63bc99d6a810af62c3695f6a9447e81c73428a38367b95534e9cb38c801ddc8896cc9f484c93ad182ad639136e0240963e06bb7dc154ec5b3bce49faaf79e
7
+ data.tar.gz: 9ead4a0fc8906c2703c2fb66e7befd317fcd6b4b6a77c0684f9c777d18e0dcf2565fc38cba2c23ce6d9935af51e534d4d80c85bcc0b6ab979a859fafa373bfb5
@@ -2,6 +2,7 @@ language: ruby
2
2
  cache: bundler
3
3
  bundler_args: --without development
4
4
  rvm:
5
+ - 2.4.1
5
6
  - 2.3.1
6
7
  - 2.1.6
7
8
  env:
@@ -1,3 +1,13 @@
1
+ # 2017-06-08 Version 0.3.0
2
+ ### Summary
3
+ Adds a new parameter for shell_ex; and improvements for local test running.
4
+
5
+ ### Features
6
+ - Implements `:chdir` option to `shell_ex`.
7
+
8
+ ### BugFixes
9
+ - Makes `my_hosts` and `logger` global methods optional.
10
+
1
11
  # 2017-06-02 Version 0.2.1
2
12
  ### Summary
3
13
  Fixes for shell_ex when running on Windows; and a minor README update.
data/README.md CHANGED
@@ -79,6 +79,8 @@ This experimental version supports only a minimal set of functionality from the
79
79
  `opts` keys:
80
80
  * `:dry_run`: set to true to skip executing the actual command.
81
81
  * `:environment`: pass environment variables for the command as a hash.
82
+ * `:chdir`: the directory in which to run the command.
83
+ * See `Process.spawn()`'s `options` argument for more attributes.
82
84
 
83
85
  Other helpful methods:
84
86
 
@@ -58,8 +58,9 @@ module Beaker
58
58
  end
59
59
 
60
60
  # execute an arbitrary command on the default host
61
- def shell_ex(cmd)
62
- shell(cmd)
61
+ def shell_ex(cmd, opts = {})
62
+ cmd = "cd #{opts[:chdir]}; " + cmd if opts.key? :chdir
63
+ shell(cmd, opts)
63
64
  end
64
65
  end
65
66
 
@@ -7,7 +7,10 @@ module Beaker
7
7
  # pass through methods to the runner
8
8
  %i[create_remote_file_ex scp_to_ex shell_ex resource execute_manifest execute_manifest_on].each do |name|
9
9
  define_method(name) do |*args|
10
- Beaker::TestmodeSwitcher.runner(hosts, logger).send(name, *args)
10
+ # `hosts`, and `logger` are beaker DSL accessors in the global scope. Do not fail here, if they're not available.
11
+ my_hosts = (hosts if respond_to? :hosts)
12
+ my_logger = (logger if respond_to? :logger)
13
+ Beaker::TestmodeSwitcher.runner(my_hosts, my_logger).send(name, *args)
11
14
  end
12
15
  end
13
16
  end
@@ -19,7 +19,7 @@ module Beaker
19
19
  if commands.empty?
20
20
  success_result
21
21
  else
22
- use_local_shell(commands.join(' && '), opts)
22
+ use_local_shell(commands.join(' && '), {})
23
23
  end
24
24
  end
25
25
 
@@ -70,8 +70,6 @@ module Beaker
70
70
  end
71
71
 
72
72
  # run a command through a local shell
73
- # Pass options to alter execution through `opts`:
74
- # * `:environment`: default: `{}`; these will be treated as extra environment variables that should be set before running the command
75
73
  def shell_ex(cmd, opts = {})
76
74
  use_local_shell(cmd, opts)
77
75
  end
@@ -87,24 +85,24 @@ module Beaker
87
85
  end
88
86
 
89
87
  # fork/exec a process and collect its output
90
- def use_local_shell(cmd, opts)
88
+ def use_local_shell(cmd, opts = {})
91
89
  if opts[:dry_run]
92
90
  puts "Would have run '#{cmd}'"
93
91
  success_result
94
92
  else
95
- capture_command(cmd, opts[:environment] || {})
93
+ capture_command(cmd, opts)
96
94
  end
97
95
  end
98
96
 
99
97
  # runs a command and captures its output in a Beaker::Result
100
- def capture_command(cmd, environment)
98
+ def capture_command(cmd, opts = {})
101
99
  blocks = {
102
100
  combined: [],
103
101
  out: [],
104
102
  err: []
105
103
  }
106
104
  exit_code = -1
107
- Open3.popen3(environment, cmd) do |stdin, stdout, stderr, wait_thr|
105
+ Open3.popen3(opts[:environment] || {}, cmd, opts) do |stdin, stdout, stderr, wait_thr|
108
106
  # TODO: pass through $stdin/terminal to subprocess to allow interaction - e.g. pry - the subprocess
109
107
  stdin.close_write
110
108
 
@@ -1,6 +1,6 @@
1
1
  module Beaker
2
2
  # central definition of this gem's version
3
3
  module TestmodeSwitcher
4
- VERSION = "0.2.1".freeze
4
+ VERSION = "0.3.0".freeze
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beaker-testmode_switcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet Labs
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: exe
14
14
  cert_chain: []
15
- date: 2017-06-02 00:00:00.000000000 Z
15
+ date: 2017-06-08 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: beaker
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  version: '0'
89
89
  requirements: []
90
90
  rubyforge_project:
91
- rubygems_version: 2.5.1
91
+ rubygems_version: 2.5.2
92
92
  signing_key:
93
93
  specification_version: 4
94
94
  summary: Let's you run your puppet module tests in master/agent, apply or local mode.