cem_win_spec 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +12 -8
- data/lib/cem_win_spec/rake_tasks.rb +1 -1
- data/lib/cem_win_spec/test_runner.rb +11 -13
- data/lib/cem_win_spec/version.rb +1 -1
- data/lib/cem_win_spec/win_exec/cmd/base_cmd.rb +11 -2
- data/lib/cem_win_spec/win_exec/exec.rb +5 -3
- data/lib/cem_win_spec/win_exec/output.rb +15 -3
- data/lib/cem_win_spec.rb +76 -31
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0f80bb9bd51e4ad8a8d005504e107a6c7761a4f8c63da2fe2df69f84e1afb1b4
|
|
4
|
+
data.tar.gz: 6eb10d5243db33711faa2b8f21914e05f3ce16cc6514ae6add15159f03c53266
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3203c1ce68eb0c392c3968b82cf80066023545b1a4522d415b1f199538bdfd7cef34c4b2e4c8bd154ddec5e95fe5fe1f5b88652aeac81f2650f8a1b27bf3a8f4
|
|
7
|
+
data.tar.gz: 8ef99fac173500c73992db6f059a704674f862bf17563a3f3aff05507eb01e715a829ea822bf6c1f3845bdae9640f90f8d178247c57ad28eb402250fc8046b48
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
cem_win_spec (0.1.
|
|
4
|
+
cem_win_spec (0.1.7)
|
|
5
5
|
parallel_tests (~> 3.4)
|
|
6
6
|
puppet_forge (~> 4.1)
|
|
7
7
|
winrm (~> 2.3)
|
|
@@ -11,17 +11,18 @@ GEM
|
|
|
11
11
|
remote: https://rubygems.org/
|
|
12
12
|
specs:
|
|
13
13
|
ast (2.4.2)
|
|
14
|
+
bigdecimal (3.1.6)
|
|
14
15
|
builder (3.2.4)
|
|
15
16
|
coderay (1.1.3)
|
|
16
17
|
diff-lcs (1.5.0)
|
|
17
18
|
erubi (1.12.0)
|
|
18
|
-
faraday (2.
|
|
19
|
-
faraday-net_http (>= 2.0, < 3.
|
|
20
|
-
ruby2_keywords (>= 0.0.4)
|
|
19
|
+
faraday (2.9.0)
|
|
20
|
+
faraday-net_http (>= 2.0, < 3.2)
|
|
21
21
|
faraday-follow_redirects (0.3.0)
|
|
22
22
|
faraday (>= 1, < 3)
|
|
23
|
-
faraday-net_http (3.0
|
|
24
|
-
|
|
23
|
+
faraday-net_http (3.1.0)
|
|
24
|
+
net-http
|
|
25
|
+
ffi (1.16.3)
|
|
25
26
|
gssapi (1.3.1)
|
|
26
27
|
ffi (>= 1.0.1)
|
|
27
28
|
gyoku (1.4.0)
|
|
@@ -35,7 +36,10 @@ GEM
|
|
|
35
36
|
method_source (1.0.0)
|
|
36
37
|
minitar (0.9)
|
|
37
38
|
multi_json (1.15.0)
|
|
38
|
-
|
|
39
|
+
net-http (0.4.1)
|
|
40
|
+
uri
|
|
41
|
+
nori (2.7.0)
|
|
42
|
+
bigdecimal
|
|
39
43
|
parallel (1.22.1)
|
|
40
44
|
parallel_tests (3.13.0)
|
|
41
45
|
parallel
|
|
@@ -78,11 +82,11 @@ GEM
|
|
|
78
82
|
rubocop-ast (1.24.1)
|
|
79
83
|
parser (>= 3.1.1.0)
|
|
80
84
|
ruby-progressbar (1.11.0)
|
|
81
|
-
ruby2_keywords (0.0.5)
|
|
82
85
|
rubyntlm (0.6.3)
|
|
83
86
|
rubyzip (2.3.2)
|
|
84
87
|
semantic_puppet (1.1.0)
|
|
85
88
|
unicode-display_width (2.1.0)
|
|
89
|
+
uri (0.13.0)
|
|
86
90
|
winrm (2.3.6)
|
|
87
91
|
builder (>= 2.1.2)
|
|
88
92
|
erubi (~> 1.8)
|
|
@@ -98,7 +98,7 @@ namespace 'cem_win_spec' do
|
|
|
98
98
|
puts "Copying Hiera config to #{hiera_fix}..."
|
|
99
99
|
::FileUtils.cp(cem_win_spec_hiera_conf, hiera_fix)
|
|
100
100
|
raise 'Hiera config copy failed!' unless File.exist?(hiera_fix)
|
|
101
|
-
|
|
101
|
+
|
|
102
102
|
puts 'Spec data prepared successfully'
|
|
103
103
|
puts 'Setting up module fixture cache...'
|
|
104
104
|
cache = CemWinSpec::FixtureCache.new
|
|
@@ -21,19 +21,11 @@ module CemWinSpec
|
|
|
21
21
|
@rspec_cmds = RspecTestCmds.new
|
|
22
22
|
@iap_tunnel = IapTunnel.new
|
|
23
23
|
@win_exec_factory = CemWinSpec::WinExec::Factory.new(@iap_tunnel, @module_archive_builder, @rspec_cmds)
|
|
24
|
+
@retry = false
|
|
24
25
|
end
|
|
25
26
|
|
|
26
|
-
def
|
|
27
|
-
|
|
28
|
-
enable_long_paths.run
|
|
29
|
-
enable_symlinks.run
|
|
30
|
-
@working_dir = create_working_dir.run
|
|
31
|
-
upload_module.run(@working_dir)
|
|
32
|
-
setup_ruby.run(@working_dir)
|
|
33
|
-
rspec_tests_parallel.run(@working_dir)
|
|
34
|
-
ensure
|
|
35
|
-
clean_up(@working_dir)
|
|
36
|
-
@iap_tunnel.stop if @iap_tunnel.running?
|
|
27
|
+
def retry?
|
|
28
|
+
@retry
|
|
37
29
|
end
|
|
38
30
|
|
|
39
31
|
def enable_long_paths(**opts)
|
|
@@ -78,6 +70,8 @@ module CemWinSpec
|
|
|
78
70
|
@setup_ruby ||= new_command('Set up ruby', **opts) do
|
|
79
71
|
remote_run(
|
|
80
72
|
[
|
|
73
|
+
'if (Test-Path .bundle) { Remove-Item -Recurse -Force .bundle }',
|
|
74
|
+
'if (Test-Path Gemfile.lock) { Remove-Item -Force Gemfile.lock }',
|
|
81
75
|
'bundle config disable_platform_warnings true',
|
|
82
76
|
'bundle config set --local without \'local_development\'',
|
|
83
77
|
'bundle install',
|
|
@@ -104,10 +98,10 @@ module CemWinSpec
|
|
|
104
98
|
end
|
|
105
99
|
end
|
|
106
100
|
|
|
107
|
-
def clean_up
|
|
101
|
+
def clean_up(working_dir)
|
|
108
102
|
@clean_up ||= new_command('Cleanup') do |working_dir|
|
|
109
103
|
if remote_available?
|
|
110
|
-
remote_run(cleanup_cmd, quiet: true)
|
|
104
|
+
remote_run(cleanup_cmd, working_dir, quiet: true)
|
|
111
105
|
else
|
|
112
106
|
logger.warn 'Cleanup not available'
|
|
113
107
|
end
|
|
@@ -120,6 +114,10 @@ module CemWinSpec
|
|
|
120
114
|
end
|
|
121
115
|
end
|
|
122
116
|
|
|
117
|
+
def inspect
|
|
118
|
+
"#<#{self.class.name}:0x#{object_id.to_s(16)}>"
|
|
119
|
+
end
|
|
120
|
+
|
|
123
121
|
private
|
|
124
122
|
|
|
125
123
|
def title_sym(title)
|
data/lib/cem_win_spec/version.rb
CHANGED
|
@@ -12,6 +12,10 @@ module CemWinSpec
|
|
|
12
12
|
'7' => '278',
|
|
13
13
|
'8' => '322',
|
|
14
14
|
}.freeze
|
|
15
|
+
TOOL_DIR_BY_RUBY_VER = {
|
|
16
|
+
'278' => 'C:/tools/ruby/2.7.8',
|
|
17
|
+
'322' => 'C:/tools/ruby/3.2.2',
|
|
18
|
+
}.freeze
|
|
15
19
|
|
|
16
20
|
attr_accessor :working_dir, :env_vars, :puppet_version
|
|
17
21
|
|
|
@@ -80,12 +84,17 @@ module CemWinSpec
|
|
|
80
84
|
logger.debug "Executing command:\n#{cmd.split(%r{\n|\r\n|;\s*}).map { |c| " #> #{c}" }.join("\n")}"
|
|
81
85
|
end
|
|
82
86
|
|
|
87
|
+
# Commands that, when ran, will change the ruby version. This will also set the local bundle config path
|
|
83
88
|
def change_ruby_version_cmd
|
|
84
|
-
|
|
89
|
+
[
|
|
90
|
+
"uru #{ruby_version}",
|
|
91
|
+
'$env:GEM_HOME = "$(ruby -e "puts Gem.dir")"',
|
|
92
|
+
'bundle config set --local path "$env:GEM_HOME"',
|
|
93
|
+
].join(COMMAND_SEPARATOR)
|
|
85
94
|
end
|
|
86
95
|
|
|
87
96
|
def set_env_var_cmd(key, value)
|
|
88
|
-
"
|
|
97
|
+
"$env:#{key} = \"#{value}\""
|
|
89
98
|
end
|
|
90
99
|
|
|
91
100
|
def change_working_dir_cmd(dir)
|
|
@@ -36,7 +36,7 @@ module CemWinSpec
|
|
|
36
36
|
|
|
37
37
|
def add_local_cmd(value)
|
|
38
38
|
raise ArgumentError, 'local_exec must implement the #run method' unless value.respond_to?(:run)
|
|
39
|
-
|
|
39
|
+
|
|
40
40
|
@local_cmd = value
|
|
41
41
|
end
|
|
42
42
|
|
|
@@ -88,7 +88,7 @@ module CemWinSpec
|
|
|
88
88
|
@ignore_exitcode = value
|
|
89
89
|
end
|
|
90
90
|
alias ignore_exitcode? ignore_exitcode
|
|
91
|
-
|
|
91
|
+
|
|
92
92
|
def success?
|
|
93
93
|
@result.success? if @result.is_a?(Output)
|
|
94
94
|
|
|
@@ -146,11 +146,13 @@ module CemWinSpec
|
|
|
146
146
|
super
|
|
147
147
|
end
|
|
148
148
|
end
|
|
149
|
-
|
|
149
|
+
|
|
150
150
|
def run(*args, **kwargs)
|
|
151
151
|
validate_instance_variables
|
|
152
152
|
logger.info "Running #{@title}"
|
|
153
153
|
result = run_with_tunnel { run_in_current_scope(*args, **kwargs) }
|
|
154
|
+
logger.debug "Command stdout: #{result.stdout}" if result.respond_to?(:stdout)
|
|
155
|
+
logger.debug "Command stderr: #{result.stderr}" if result.respond_to?(:stderr)
|
|
154
156
|
@result = Output.new(result)
|
|
155
157
|
return if @result.pending_threaded?
|
|
156
158
|
|
|
@@ -53,19 +53,31 @@ module CemWinSpec
|
|
|
53
53
|
end
|
|
54
54
|
out_array.compact!
|
|
55
55
|
return if out_array.empty?
|
|
56
|
-
|
|
56
|
+
|
|
57
57
|
logger.info "#{stream_name.to_s.upcase}:\n#{out_array.join("\n")}"
|
|
58
58
|
end
|
|
59
59
|
|
|
60
|
+
def to_s
|
|
61
|
+
return '' if @raw_output.nil?
|
|
62
|
+
|
|
63
|
+
format_output_string(@raw_output.to_s)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def inspect
|
|
67
|
+
"#<#{self.class}:#{object_id} exitcode=#{exitcode.inspect} stdout=#{stdout.inspect} stderr=#{stderr.inspect}>"
|
|
68
|
+
end
|
|
69
|
+
|
|
60
70
|
private
|
|
61
71
|
|
|
62
72
|
def format_output_string(str)
|
|
63
73
|
# Cut the number of spaces in half, replace tabs with double spaces
|
|
64
74
|
str.gsub!(/\s\s/, ' ')
|
|
65
75
|
str.gsub!(/\t/, ' ')
|
|
66
|
-
return "#{@line_prefix}#{str}" if str.length <=
|
|
76
|
+
return "#{@line_prefix}#{str}" if str.length <= 180
|
|
67
77
|
|
|
68
|
-
str.scan(/.{1,
|
|
78
|
+
str.scan(/.{1,180}/).map { |s| "#{@line_prefix}#{s}" }.instance_eval { |a|
|
|
79
|
+
[a.first] + a.drop(1).map { |s| " #{s}" }
|
|
80
|
+
}.join("\n")
|
|
69
81
|
end
|
|
70
82
|
|
|
71
83
|
def set_vars_from_output(out)
|
data/lib/cem_win_spec.rb
CHANGED
|
@@ -40,23 +40,22 @@ module CemWinSpec
|
|
|
40
40
|
logger.debug 'Set up signal handler'
|
|
41
41
|
begin
|
|
42
42
|
sre_out = setup_remote_environment(runner)
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
working_dir = sre_out.stdout.chomp
|
|
44
|
+
logger.debug "Working dir: #{working_dir}"
|
|
45
|
+
upload_out = upload_module(runner, working_dir)
|
|
46
|
+
module_dir = upload_out.stdout.chomp
|
|
45
47
|
logger.debug "Module dir: #{module_dir}"
|
|
46
|
-
|
|
47
|
-
check_output!(srr_out, runner)
|
|
48
|
+
setup_remote_ruby(runner, module_dir, **options)
|
|
48
49
|
case operation
|
|
49
50
|
when :spec
|
|
50
|
-
|
|
51
|
-
check_output!(spec_out, runner)
|
|
51
|
+
run_spec(runner, module_dir, **options)
|
|
52
52
|
when :clean_fixture_cache
|
|
53
|
-
|
|
54
|
-
check_output!(clean_fixture_cache_out, runner)
|
|
53
|
+
clean_fixture_cache(runner, module_dir, **options)
|
|
55
54
|
else
|
|
56
55
|
raise ArgumentError, "Unknown operation: #{operation}"
|
|
57
56
|
end
|
|
58
57
|
rescue StandardError => e
|
|
59
|
-
if operation == :spec
|
|
58
|
+
if operation == :spec && runner.retry?
|
|
60
59
|
begin
|
|
61
60
|
logger.warn "Error running spec: #{e.message}"
|
|
62
61
|
logger.debug e.backtrace.join("\n")
|
|
@@ -67,6 +66,9 @@ module CemWinSpec
|
|
|
67
66
|
else
|
|
68
67
|
handle_run_error(e)
|
|
69
68
|
end
|
|
69
|
+
ensure
|
|
70
|
+
runner&.clean_up(working_dir) if working_dir
|
|
71
|
+
runner&.iap_tunnel&.stop(wait: false, log: false)
|
|
70
72
|
end
|
|
71
73
|
end
|
|
72
74
|
|
|
@@ -78,43 +80,60 @@ module CemWinSpec
|
|
|
78
80
|
|
|
79
81
|
def self.retry_spec_on_error(runner, module_dir, **options)
|
|
80
82
|
logger.info 'Cleaning cache and trying again...'
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
validate_output do
|
|
84
|
+
clean_fixture_cache(runner, module_dir, **options)
|
|
85
|
+
end
|
|
86
|
+
validate_output do
|
|
87
|
+
run_spec(runner, module_dir, **options)
|
|
88
|
+
end
|
|
85
89
|
end
|
|
86
90
|
|
|
87
91
|
def self.setup_remote_environment(runner)
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
validate_output do
|
|
93
|
+
runner.enable_long_paths.run
|
|
94
|
+
end
|
|
95
|
+
validate_output do
|
|
96
|
+
runner.enable_symlinks.run
|
|
97
|
+
end
|
|
98
|
+
validate_output do
|
|
99
|
+
runner.create_working_dir.run
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def self.upload_module(runner, working_dir)
|
|
104
|
+
validate_output do
|
|
105
|
+
runner.upload_module(operation_timeout: 300, receive_timeout: 310, working_dir: working_dir).run
|
|
106
|
+
end
|
|
94
107
|
end
|
|
95
108
|
|
|
96
109
|
def self.setup_remote_ruby(runner, module_dir, **opts)
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
110
|
+
validate_output do
|
|
111
|
+
runner.setup_ruby(operation_timeout: 300,
|
|
112
|
+
receive_timeout: 310,
|
|
113
|
+
working_dir: module_dir,
|
|
114
|
+
reuse_tunnel: false,
|
|
115
|
+
**opts).run
|
|
116
|
+
end
|
|
102
117
|
end
|
|
103
118
|
|
|
104
119
|
# Runs RSpec tests
|
|
105
120
|
def self.run_spec(runner, module_dir, **opts)
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
121
|
+
output = validate_output(validation_method: :inspect) do
|
|
122
|
+
runner.rspec_tests_parallel(operation_timeout: 300,
|
|
123
|
+
receive_timeout: 310,
|
|
124
|
+
working_dir: module_dir,
|
|
125
|
+
ignore_exitcode: true,
|
|
126
|
+
reuse_tunnel: false,
|
|
127
|
+
**opts).run
|
|
128
|
+
end
|
|
112
129
|
end
|
|
113
130
|
|
|
114
131
|
# Clean the remote fixture cache
|
|
115
132
|
# @param options [Hash] Options for the test runner
|
|
116
133
|
def self.clean_fixture_cache(runner, module_dir, **opts)
|
|
117
|
-
|
|
134
|
+
validate_output do
|
|
135
|
+
runner.clean_fixture_cache(working_dir: module_dir, **opts).run
|
|
136
|
+
end
|
|
118
137
|
end
|
|
119
138
|
|
|
120
139
|
def self.check_output!(output, runner = nil)
|
|
@@ -123,4 +142,30 @@ module CemWinSpec
|
|
|
123
142
|
raise "Command failed with exit code #{output.exitcode}"
|
|
124
143
|
end
|
|
125
144
|
end
|
|
145
|
+
|
|
146
|
+
class CemWinSpecValidationError < StandardError; end
|
|
147
|
+
|
|
148
|
+
def self.validate_output(*args, validation_method: :success?, no_output_strat: :debug, **kwargs)
|
|
149
|
+
raise ArgumentError, 'Block required' unless block_given?
|
|
150
|
+
|
|
151
|
+
output = yield *args, **kwargs
|
|
152
|
+
unless output
|
|
153
|
+
case no_output_strat
|
|
154
|
+
when :raise
|
|
155
|
+
raise 'No output'
|
|
156
|
+
when :warn
|
|
157
|
+
logger.warn 'No output'
|
|
158
|
+
when :debug
|
|
159
|
+
logger.debug 'No output'
|
|
160
|
+
else
|
|
161
|
+
# Do nothing
|
|
162
|
+
end
|
|
163
|
+
return false
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
unless output.send(validation_method)
|
|
167
|
+
raise CemWinSpecValidationError, "Output validation \"#{validation_method}\" failed: #{output}"
|
|
168
|
+
end
|
|
169
|
+
output
|
|
170
|
+
end
|
|
126
171
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cem_win_spec
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Heston Snodgrass
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2024-03-29 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: winrm
|
|
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
139
139
|
- !ruby/object:Gem::Version
|
|
140
140
|
version: '0'
|
|
141
141
|
requirements: []
|
|
142
|
-
rubygems_version: 3.4.
|
|
142
|
+
rubygems_version: 3.4.22
|
|
143
143
|
signing_key:
|
|
144
144
|
specification_version: 4
|
|
145
145
|
summary: Write a short summary, because RubyGems requires one.
|