puppet-ci-testing 0.14.3 → 0.16.1
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 +5 -5
- data/bin/check_file_syntax +9 -9
- data/lib/check_file_syntax.rb +76 -16
- data/lib/simple_junit.rb +2 -2
- data/spec/check_file_syntax_spec.rb +44 -27
- data/spec/file_generators.rb +211 -0
- data/spec/simple_junit_spec.rb +36 -37
- data/spec/spec_helper.rb +2 -181
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '09db4de24d2d8e1e8bb604cd574bf11b5a05ca169ac8e48d65cba8854947602d'
|
4
|
+
data.tar.gz: 6b325a5203b582736e39df99aba994dc72bc966d3353c2fa20b24c2dd8b7d768
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83565908b56c3f01487079742f790304d274fa700fa16a60941cfb7f87be76f392cddf07f6801ad811426031fa98b0b40e5541e96f1be4dcebed65ffec0347eb
|
7
|
+
data.tar.gz: bea9c2bfe42f523f6537fecd99f19832eaa7e27222ed19251328a2e7fd5826cf75019881e96d39fa24f34557544bbc9ddbbc1ccc7caac13cdb5d8d386c3012c0
|
data/bin/check_file_syntax
CHANGED
@@ -58,7 +58,7 @@ EOH
|
|
58
58
|
opts.on('--git-hook', '-g', 'Execute as a Git pre-commit hook') do
|
59
59
|
options[:git_hook] = true
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
opts.on('--initialize', '--init', '-I', 'Setup Git pre-commit hook') do
|
63
63
|
# insure that we see the .git directory
|
64
64
|
unless Dir.exists? '.git'
|
@@ -66,26 +66,26 @@ EOH
|
|
66
66
|
puts "Please rerun the command at the top of the Git directory tree."
|
67
67
|
exit 1
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
# insure that the hooks directory exists
|
71
71
|
unless Dir.exists? '.git/hooks'
|
72
72
|
FileUtils.mkdir '.git/hooks', :mode => 0755
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
# Now create the pre-commit file unless it exists
|
76
76
|
if File.exists? '.git/hooks/pre-commit'
|
77
77
|
puts "The Git pre-commit hook already exists (.git/hooks/pre-commit)."
|
78
78
|
puts "Please remove this file and rerun the command to create the pre-commit hook."
|
79
79
|
exit 1
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
open('.git/hooks/pre-commit', 'w') do |fp|
|
83
|
-
fp.puts "#{$0} --git-hook || (echo '[1m[31mpuppet-ci-testing gem is not installed[0m' && exit 1)"
|
83
|
+
fp.puts "#{File.basename $0} --git-hook || (echo '[1m[31mpuppet-ci-testing gem is not installed[0m' && exit 1)"
|
84
84
|
end
|
85
85
|
FileUtils.chmod 0755, '.git/hooks/pre-commit'
|
86
86
|
exit 0
|
87
87
|
end
|
88
|
-
|
88
|
+
|
89
89
|
end.parse!
|
90
90
|
|
91
91
|
# check for an optional directory to
|
@@ -113,11 +113,11 @@ else
|
|
113
113
|
tc = test_suite.create_testcase('File syntax', path)
|
114
114
|
case status
|
115
115
|
when :passed
|
116
|
-
tc.
|
116
|
+
tc.pass(output: output)
|
117
117
|
when :failed
|
118
|
-
tc.
|
118
|
+
tc.fail(type: 'syntax_error', output: '', error: output)
|
119
119
|
when :skipped
|
120
|
-
tc.
|
120
|
+
tc.skip
|
121
121
|
end
|
122
122
|
end
|
123
123
|
end
|
data/lib/check_file_syntax.rb
CHANGED
@@ -2,7 +2,30 @@ require 'colorize'
|
|
2
2
|
require 'json'
|
3
3
|
require 'yaml'
|
4
4
|
require 'find'
|
5
|
+
require 'net/https'
|
6
|
+
require 'uri'
|
7
|
+
|
8
|
+
module Net
|
9
|
+
class HTTP
|
10
|
+
def self.enable_debug!
|
11
|
+
class << self
|
12
|
+
alias_method :__new__, :new
|
13
|
+
def new(*args, &blk)
|
14
|
+
instance = __new__(*args, &blk)
|
15
|
+
instance.set_debug_output($stderr)
|
16
|
+
instance
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
5
20
|
|
21
|
+
def self.disable_debug!
|
22
|
+
class << self
|
23
|
+
alias_method :new, :__new__
|
24
|
+
remove_method :__new__
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
6
29
|
|
7
30
|
module CheckFileSyntax
|
8
31
|
|
@@ -38,7 +61,7 @@ module CheckFileSyntax
|
|
38
61
|
end
|
39
62
|
|
40
63
|
def ruby_file?(path)
|
41
|
-
type_of_file(path, :ruby, '.rb')
|
64
|
+
type_of_file(path, :ruby, ['.rb', '.rake'])
|
42
65
|
end
|
43
66
|
|
44
67
|
def perl_file?(path)
|
@@ -57,6 +80,9 @@ module CheckFileSyntax
|
|
57
80
|
type_of_file(path, '---', ['.yaml', '.yml'])
|
58
81
|
end
|
59
82
|
|
83
|
+
def gitlab_ci_file?(path)
|
84
|
+
type_of_file(path, :gitlab_ci, '.gitlab-ci.yml')
|
85
|
+
end
|
60
86
|
|
61
87
|
module_function
|
62
88
|
def show_status (name, success, errors)
|
@@ -116,14 +142,12 @@ module CheckFileSyntax
|
|
116
142
|
puts 'Consider installing puppet so that syntax can be checked.'.colorize(:yellow)
|
117
143
|
status = :skipped
|
118
144
|
end
|
119
|
-
end
|
120
145
|
|
121
|
-
|
146
|
+
elsif erb_file? path
|
122
147
|
errors = `cat #{path} | erb -x -T - | ruby -c 2>&1`
|
123
148
|
status = $?.success? ? :passed : :failed
|
124
|
-
end
|
125
149
|
|
126
|
-
|
150
|
+
elsif python_file? path
|
127
151
|
if system('which python >/dev/null')
|
128
152
|
errors = `python -m py_compile #{path} 2>&1`
|
129
153
|
status = $?.success? ? :passed : :failed
|
@@ -131,14 +155,12 @@ module CheckFileSyntax
|
|
131
155
|
puts 'Consider installing python so that syntax can be checked.'.colorize(:yellow)
|
132
156
|
status = :skipped
|
133
157
|
end
|
134
|
-
end
|
135
158
|
|
136
|
-
|
159
|
+
elsif ruby_file? path
|
137
160
|
errors = `ruby -c #{path} 2>&1`
|
138
161
|
status = $?.success? ? :passed : :failed
|
139
|
-
end
|
140
162
|
|
141
|
-
|
163
|
+
elsif perl_file? path
|
142
164
|
if system('which perl >/dev/null')
|
143
165
|
errors = `perl -c #{path} 2>&1`
|
144
166
|
status = $?.success? ? :passed : :failed
|
@@ -146,15 +168,52 @@ module CheckFileSyntax
|
|
146
168
|
puts 'Consider installing perl so that syntax can be checked.'.colorize(:yellow)
|
147
169
|
status = :skipped
|
148
170
|
end
|
149
|
-
end
|
150
171
|
|
151
|
-
|
172
|
+
elsif bash_file? path
|
152
173
|
errors = `bash -n #{path} 2>&1`.to_i
|
153
174
|
status = $?.success? ? :passed : :failed
|
154
|
-
end
|
155
175
|
|
176
|
+
# GitLab CI files need to be processed before YAML
|
177
|
+
elsif gitlab_ci_file? path
|
178
|
+
ci_content = YAML.load_file(path)
|
179
|
+
|
180
|
+
if ENV.has_key?('CI_LINT_TOKEN')
|
181
|
+
priv_token = ENV['CI_LINT_TOKEN']
|
182
|
+
else
|
183
|
+
token_file = "#{Dir.home}/.gitlab-tokens"
|
184
|
+
if File.readable?(token_file)
|
185
|
+
tokens = YAML.load_file(token_file)
|
186
|
+
# Any token should work
|
187
|
+
priv_token = tokens.values()[0]
|
188
|
+
end
|
189
|
+
end
|
156
190
|
|
157
|
-
|
191
|
+
begin
|
192
|
+
uri = URI.parse('https://gitlab.com/api/v4/ci/lint')
|
193
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
194
|
+
http.use_ssl = true
|
195
|
+
Net::HTTP.enable_debug!
|
196
|
+
request = Net::HTTP::Post.new(uri.path, {
|
197
|
+
'Content-Type' => 'application/json',
|
198
|
+
'Accept' => 'application/json',
|
199
|
+
'PRIVATE-TOKEN' => priv_token
|
200
|
+
})
|
201
|
+
request.body = {content: ci_content.to_json}.to_json
|
202
|
+
response = http.request(request)
|
203
|
+
puts response
|
204
|
+
rescue => e
|
205
|
+
puts "Exception: #{e}"
|
206
|
+
end
|
207
|
+
results = JSON.parse(response.body)
|
208
|
+
case results['status']
|
209
|
+
when 'valid'
|
210
|
+
status = :passed
|
211
|
+
when 'invalid'
|
212
|
+
status = :failed
|
213
|
+
errors = results['errors']
|
214
|
+
end
|
215
|
+
|
216
|
+
elsif json_file? path
|
158
217
|
begin
|
159
218
|
JSON.parse(File.read(path))
|
160
219
|
status = :passed
|
@@ -162,9 +221,8 @@ module CheckFileSyntax
|
|
162
221
|
errors = e.message
|
163
222
|
status = :failed
|
164
223
|
end
|
165
|
-
end
|
166
224
|
|
167
|
-
|
225
|
+
elsif yaml_file? path
|
168
226
|
begin
|
169
227
|
YAML.parse(File.read(path))
|
170
228
|
status = :passed
|
@@ -181,4 +239,6 @@ module CheckFileSyntax
|
|
181
239
|
error_count += 1 if status == :failed
|
182
240
|
end
|
183
241
|
end
|
184
|
-
end
|
242
|
+
end
|
243
|
+
|
244
|
+
|
data/lib/simple_junit.rb
CHANGED
@@ -90,7 +90,7 @@ EOTS
|
|
90
90
|
@output = nil
|
91
91
|
end
|
92
92
|
|
93
|
-
def
|
93
|
+
def pass(output:nil, error:nil)
|
94
94
|
@status = :passed
|
95
95
|
unless output.nil?
|
96
96
|
@output = output
|
@@ -104,7 +104,7 @@ EOTS
|
|
104
104
|
@status == :passed
|
105
105
|
end
|
106
106
|
|
107
|
-
def
|
107
|
+
def fail(type:nil, output:nil, error:nil)
|
108
108
|
@status = :failed
|
109
109
|
@error_type = type || 'unspecified'
|
110
110
|
unless output.nil?
|
@@ -1,31 +1,42 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'check_file_syntax'
|
3
|
+
require 'fileutils'
|
3
4
|
|
4
5
|
describe CheckFileSyntax do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
|
7
|
+
after(:all) do
|
8
|
+
# clean up after testing
|
9
|
+
if Dir.exists? '__pycache__'
|
10
|
+
FileUtils.rm_rf '__pycache__'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
{ :json => '.json',
|
16
|
+
:yaml => ['.yaml','.yml'],
|
17
|
+
:perl => ['.pl','.pm'],
|
18
|
+
:bash => ['.sh','.bash','.zsh','.ksh'],
|
19
|
+
:ruby => '.rb',
|
20
|
+
:python => '.py',
|
21
|
+
:erb => '.erb',
|
22
|
+
:puppet => '.pp',
|
23
|
+
:gitlab_ci => '.gitlab-ci.yml' }.each_pair do |type, exts|
|
14
24
|
[exts].flatten.each do |ext|
|
15
25
|
it "identifies #{type} with #{ext} extension" do
|
16
26
|
expect(CheckFileSyntax::type_of_file("foo#{ext}", type, exts)).to eq true
|
17
27
|
end
|
18
28
|
end
|
19
29
|
end
|
20
|
-
|
21
|
-
{ :json
|
22
|
-
:yaml
|
23
|
-
:perl
|
24
|
-
:bash
|
25
|
-
:ruby
|
26
|
-
:python
|
27
|
-
:erb
|
28
|
-
:puppet
|
30
|
+
|
31
|
+
{ :json => '.json',
|
32
|
+
:yaml => ['.yaml','.yml'],
|
33
|
+
:perl => ['.pl','.pm'],
|
34
|
+
:bash => ['.sh','.bash','.zsh','.ksh'],
|
35
|
+
:ruby => '.rb',
|
36
|
+
:python => '.py',
|
37
|
+
:erb => '.erb',
|
38
|
+
:puppet => '.pp',
|
39
|
+
:gitlab_ci => '.gitlab-ci.yml' }.each_pair do |type, exts|
|
29
40
|
bad_ext = random_string(8)
|
30
41
|
[exts].flatten.each do |ext|
|
31
42
|
it "fails identifying #{type} without #{ext} extension" do
|
@@ -33,11 +44,11 @@ describe CheckFileSyntax do
|
|
33
44
|
end
|
34
45
|
end
|
35
46
|
end
|
36
|
-
|
47
|
+
|
37
48
|
CheckFileSyntax::ALL_CHECKS.each do |type|
|
38
49
|
bad_ext ||= random_string(8)
|
39
50
|
# Puppet, ERB, JSON and YAML files don't have shebang lines
|
40
|
-
unless [:puppet, :erb, :json, :yaml].include? type
|
51
|
+
unless [:puppet, :erb, :json, :yaml, :gitlab_ci].include? type
|
41
52
|
it "identifies content as #{type}" do
|
42
53
|
filename = eval "generate_#{type.to_s}(:valid, extension:'.#{bad_ext}')"
|
43
54
|
expect(CheckFileSyntax::type_of_file(filename, type, '.foo')).to eq true
|
@@ -45,15 +56,21 @@ describe CheckFileSyntax do
|
|
45
56
|
end
|
46
57
|
end
|
47
58
|
end
|
48
|
-
|
59
|
+
|
49
60
|
CheckFileSyntax::ALL_CHECKS.each do |type|
|
50
61
|
it "identifies valid syntax of #{type}" do
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
62
|
+
begin
|
63
|
+
filename = eval "generate_#{type.to_s}(:valid)"
|
64
|
+
CheckFileSyntax::check_file_syntax(filename) { |path, status, errors|
|
65
|
+
expect(status).to eq :passed
|
66
|
+
}
|
67
|
+
rescue Exception => e
|
68
|
+
puts e
|
69
|
+
end
|
55
70
|
File.unlink filename
|
56
|
-
File.
|
71
|
+
if type == :python and File.exists? "#{filename}c"
|
72
|
+
File.unlink "#{filename}c"
|
73
|
+
end
|
57
74
|
end
|
58
75
|
end
|
59
76
|
|
@@ -66,5 +83,5 @@ describe CheckFileSyntax do
|
|
66
83
|
File.unlink filename
|
67
84
|
end
|
68
85
|
end
|
69
|
-
|
86
|
+
|
70
87
|
end
|
@@ -0,0 +1,211 @@
|
|
1
|
+
def generate_json(validity, extension: '.json')
|
2
|
+
filebase = random_string(16)
|
3
|
+
if validity == :valid
|
4
|
+
open(filebase + extension, 'w') do |fh|
|
5
|
+
fh.puts <<EOF
|
6
|
+
{
|
7
|
+
"test": "good JSON",
|
8
|
+
"foo": "bar"
|
9
|
+
}
|
10
|
+
EOF
|
11
|
+
end
|
12
|
+
elsif validity == :invalid
|
13
|
+
open(filebase + extension, 'w') do |fh|
|
14
|
+
fh.puts <<EOF
|
15
|
+
{
|
16
|
+
"test": "bad JSON"
|
17
|
+
"foo": "bar"
|
18
|
+
}
|
19
|
+
EOF
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
return filebase + extension
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def generate_yaml(validity, extension: '.yaml')
|
28
|
+
filebase = random_string(16)
|
29
|
+
if validity == :valid
|
30
|
+
open(filebase + extension, 'w') do |fh|
|
31
|
+
fh.puts <<EOF
|
32
|
+
---
|
33
|
+
test: "good YAML"
|
34
|
+
foo: "bar"
|
35
|
+
EOF
|
36
|
+
end
|
37
|
+
elsif validity == :invalid
|
38
|
+
open(filebase + extension, 'w') do |fh|
|
39
|
+
fh.puts <<EOF
|
40
|
+
===
|
41
|
+
test: "bad YAML",
|
42
|
+
foo: "bar"
|
43
|
+
EOF
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
return filebase + extension
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
def generate_ruby(validity, extension: '.rb')
|
52
|
+
filebase = random_string(16)
|
53
|
+
if validity == :valid
|
54
|
+
open(filebase + extension, 'w') do |fh|
|
55
|
+
fh.puts <<EOF
|
56
|
+
#!/usr/bin/env ruby
|
57
|
+
puts "valid ruby!"
|
58
|
+
EOF
|
59
|
+
end
|
60
|
+
elsif validity == :invalid
|
61
|
+
open(filebase + extension, 'w') do |fh|
|
62
|
+
fh.puts <<EOF
|
63
|
+
#!/usr/bin/env ruby
|
64
|
+
put "invalid ruby!'
|
65
|
+
EOF
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
return filebase + extension
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
def generate_python(validity, extension: '.py')
|
74
|
+
filebase = random_string(16)
|
75
|
+
if validity == :valid
|
76
|
+
open(filebase + extension, 'w') do |fh|
|
77
|
+
fh.puts <<EOF
|
78
|
+
#!/usr/bin/env python
|
79
|
+
print("valid python!")
|
80
|
+
EOF
|
81
|
+
end
|
82
|
+
elsif validity == :invalid
|
83
|
+
open(filebase + extension, 'w') do |fh|
|
84
|
+
fh.puts <<EOF
|
85
|
+
#!/usr/bin/env python
|
86
|
+
print("invalid python!')
|
87
|
+
EOF
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
return filebase + extension
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
def generate_perl(validity, extension: '.pl')
|
96
|
+
filebase = random_string(16)
|
97
|
+
if validity == :valid
|
98
|
+
open(filebase + extension, 'w') do |fh|
|
99
|
+
fh.puts <<EOF
|
100
|
+
#!/usr/bin/env perl
|
101
|
+
print "valid ";
|
102
|
+
print "perl!"
|
103
|
+
EOF
|
104
|
+
end
|
105
|
+
elsif validity == :invalid
|
106
|
+
open(filebase + extension, 'w') do |fh|
|
107
|
+
fh.puts <<EOF
|
108
|
+
#!/usr/bin/env perl
|
109
|
+
print "invalid "
|
110
|
+
print "perl!"
|
111
|
+
EOF
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
return filebase + extension
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
def generate_bash(validity, extension: '.sh')
|
120
|
+
filebase = random_string(16)
|
121
|
+
if validity == :valid
|
122
|
+
open(filebase + extension, 'w') do |fh|
|
123
|
+
fh.puts <<EOF
|
124
|
+
#!/bin/bash
|
125
|
+
echo "valid shell!"
|
126
|
+
EOF
|
127
|
+
end
|
128
|
+
elsif validity == :invalid
|
129
|
+
open(filebase + extension, 'w') do |fh|
|
130
|
+
fh.puts <<EOF
|
131
|
+
#!/bin/bash
|
132
|
+
echo "invalid shell!'
|
133
|
+
EOF
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
return filebase + extension
|
138
|
+
end
|
139
|
+
|
140
|
+
|
141
|
+
def generate_erb(validity, extension: '.erb')
|
142
|
+
filebase = random_string(16)
|
143
|
+
if validity == :valid
|
144
|
+
open(filebase + extension, 'w') do |fh|
|
145
|
+
fh.puts <<EOF
|
146
|
+
<% puts "valid erb!" %>
|
147
|
+
EOF
|
148
|
+
end
|
149
|
+
elsif validity == :invalid
|
150
|
+
open(filebase + extension, 'w') do |fh|
|
151
|
+
fh.puts <<EOF
|
152
|
+
<% puts "invalid " <%= erb!" %>
|
153
|
+
EOF
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
return filebase + extension
|
158
|
+
end
|
159
|
+
|
160
|
+
|
161
|
+
def generate_puppet(validity, extension: '.pp')
|
162
|
+
filebase = random_string(16)
|
163
|
+
if validity == :valid
|
164
|
+
open(filebase + extension, 'w') do |fh|
|
165
|
+
fh.puts <<EOF
|
166
|
+
puppet { 'good': }
|
167
|
+
EOF
|
168
|
+
end
|
169
|
+
elsif validity == :invalid
|
170
|
+
open(filebase + extension, 'w') do |fh|
|
171
|
+
fh.puts <<EOF
|
172
|
+
puppet { "bad" }
|
173
|
+
EOF
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
return filebase + extension
|
178
|
+
end
|
179
|
+
|
180
|
+
|
181
|
+
def generate_gitlab_ci(validity, extension: '.gitlab-ci.yml')
|
182
|
+
filebase = random_string(16)
|
183
|
+
if validity == :valid
|
184
|
+
open(filebase + extension, 'w') do |fh|
|
185
|
+
fh.puts <<EOF
|
186
|
+
stages:
|
187
|
+
- stage1
|
188
|
+
|
189
|
+
job1:
|
190
|
+
stage: stage1
|
191
|
+
script:
|
192
|
+
- echo "test"
|
193
|
+
EOF
|
194
|
+
end
|
195
|
+
elsif validity == :invalid
|
196
|
+
open(filebase + extension, 'w') do |fh|
|
197
|
+
fh.puts <<EOF
|
198
|
+
stages:
|
199
|
+
stage1:
|
200
|
+
|
201
|
+
job1:
|
202
|
+
stage: stage2
|
203
|
+
script:
|
204
|
+
echo "test"
|
205
|
+
echo "test2"
|
206
|
+
EOF
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
return filebase + extension
|
211
|
+
end
|
data/spec/simple_junit_spec.rb
CHANGED
@@ -2,13 +2,13 @@ require 'spec_helper'
|
|
2
2
|
require 'simple_junit'
|
3
3
|
|
4
4
|
describe 'SimpleJUnit' do
|
5
|
-
describe 'TestSuiteCollection' do
|
5
|
+
describe 'TestSuiteCollection' do
|
6
6
|
it 'creates an empty test suite collection' do
|
7
7
|
tc = SimpleJUnit::TestSuiteCollection.instance
|
8
8
|
expect(tc.testsuites).to eq []
|
9
9
|
tc.reset
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
it 'creates two test suite collections' do
|
13
13
|
tc = SimpleJUnit::TestSuiteCollection.instance
|
14
14
|
tc.create_testsuite('foo')
|
@@ -16,14 +16,14 @@ describe 'SimpleJUnit' do
|
|
16
16
|
expect(tc.testsuites.count).to eq 2
|
17
17
|
tc.reset
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
it 'generates valid JUnit XML output' do
|
21
21
|
tc = SimpleJUnit::TestSuiteCollection.instance
|
22
22
|
xml = tc.to_s.gsub(/\n\s*/, "")
|
23
23
|
expect(xml).to match /<\?xml version="1.0" encoding="UTF-8"\?><testsuites><\/testsuites>/
|
24
24
|
tc.reset
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
it 'generates valid JUnit XML output with test suites' do
|
28
28
|
tc = SimpleJUnit::TestSuiteCollection.instance
|
29
29
|
tc.create_testsuite('foo')
|
@@ -35,104 +35,104 @@ describe 'SimpleJUnit' do
|
|
35
35
|
tc.reset
|
36
36
|
end
|
37
37
|
end
|
38
|
-
|
39
|
-
|
38
|
+
|
39
|
+
|
40
40
|
describe 'TestSuite' do
|
41
41
|
it 'generates valid XML' do
|
42
42
|
name = random_string(5)
|
43
43
|
ts = SimpleJUnit::TestSuite.new(name)
|
44
44
|
t1 = random_string(3)
|
45
|
-
ts.create_testcase(t1).
|
45
|
+
ts.create_testcase(t1).pass
|
46
46
|
t2 = random_string(3)
|
47
|
-
ts.create_testcase(t2).
|
47
|
+
ts.create_testcase(t2).fail
|
48
48
|
t3 = random_string(3)
|
49
|
-
ts.create_testcase(t3).
|
49
|
+
ts.create_testcase(t3).fail
|
50
50
|
t4 = random_string(3)
|
51
|
-
ts.create_testcase(t4).
|
51
|
+
ts.create_testcase(t4).pass
|
52
52
|
t5 = random_string(3)
|
53
53
|
ts.create_testcase(t5).skip
|
54
54
|
xml = ts.to_s.gsub(/\n\s*/, "")
|
55
55
|
expect(xml).to match /<testsuite name="#{name}" errors="0" tests="5" failures="2" time="0" timestamp="[^"]+"><properties\/><testcase classname="#{t1}" time=""><\/testcase><testcase classname="#{t2}" time=""><failure message="unspecified"><\/failure><\/testcase><testcase classname="#{t3}" time=""><failure message="unspecified"><\/failure><\/testcase><testcase classname="#{t4}" time=""><\/testcase><testcase classname="#{t5}" time=""><skipped\/><\/testcase><\/testsuite>/
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
end
|
59
|
-
|
60
|
-
|
59
|
+
|
60
|
+
|
61
61
|
describe 'TestCase' do
|
62
|
-
it '
|
62
|
+
it 'pass() sets internal state correctly' do
|
63
63
|
t = SimpleJUnit::TestCase.new('foo')
|
64
64
|
output = random_string(30)
|
65
65
|
error = random_string(20)
|
66
|
-
t.
|
66
|
+
t.pass(output: output, error: error)
|
67
67
|
expect(t.status).to eq :passed
|
68
68
|
expect(t.output).to eq output
|
69
69
|
expect(t.errors).to eq error
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
it 'passed? test correct' do
|
73
73
|
t = SimpleJUnit::TestCase.new('foo')
|
74
74
|
expect(t.passed?).to eq false
|
75
|
-
t.
|
75
|
+
t.pass
|
76
76
|
expect(t.passed?).to eq true
|
77
|
-
t.
|
77
|
+
t.fail
|
78
78
|
expect(t.passed?).to eq false
|
79
79
|
t.skip
|
80
80
|
expect(t.passed?).to eq false
|
81
81
|
end
|
82
|
-
|
83
|
-
it '
|
82
|
+
|
83
|
+
it 'fail() sets internal state correctly with error type' do
|
84
84
|
t = SimpleJUnit::TestCase.new('foo')
|
85
85
|
output = random_string(30)
|
86
86
|
error = random_string(20)
|
87
|
-
t.
|
87
|
+
t.fail(type:'bar', output:output, error:error)
|
88
88
|
expect(t.status).to eq :failed
|
89
89
|
expect(t.output).to eq output
|
90
90
|
expect(t.errors).to eq error
|
91
91
|
end
|
92
|
-
|
93
|
-
it '
|
92
|
+
|
93
|
+
it 'fail() sets internal state correctly without error type' do
|
94
94
|
t = SimpleJUnit::TestCase.new('foo')
|
95
95
|
output = random_string(30)
|
96
96
|
error = random_string(20)
|
97
|
-
t.
|
97
|
+
t.fail(:output => output, :error => error)
|
98
98
|
expect(t.status).to eq :failed
|
99
99
|
expect(t.output).to eq output
|
100
100
|
expect(t.errors).to eq error
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
it 'failed? test correct' do
|
104
104
|
t = SimpleJUnit::TestCase.new('foo')
|
105
105
|
expect(t.failed?).to eq false
|
106
|
-
t.
|
106
|
+
t.fail
|
107
107
|
expect(t.failed?).to eq true
|
108
|
-
t.
|
108
|
+
t.pass
|
109
109
|
expect(t.failed?).to eq false
|
110
110
|
t.skip
|
111
111
|
expect(t.passed?).to eq false
|
112
112
|
end
|
113
|
-
|
113
|
+
|
114
114
|
it 'pending? test correct' do
|
115
115
|
t = SimpleJUnit::TestCase.new('foo')
|
116
116
|
expect(t.pending?).to eq true
|
117
|
-
t.
|
117
|
+
t.fail
|
118
118
|
expect(t.pending?).to eq false
|
119
|
-
t.
|
119
|
+
t.pass
|
120
120
|
expect(t.pending?).to eq false
|
121
121
|
t.skip
|
122
122
|
expect(t.pending?).to eq false
|
123
123
|
end
|
124
|
-
|
124
|
+
|
125
125
|
it 'skipped? test correct' do
|
126
126
|
t = SimpleJUnit::TestCase.new('foo')
|
127
127
|
expect(t.skipped?).to eq false
|
128
|
-
t.
|
128
|
+
t.fail
|
129
129
|
expect(t.skipped?).to eq false
|
130
|
-
t.
|
130
|
+
t.pass
|
131
131
|
expect(t.skipped?).to eq false
|
132
132
|
t.skip
|
133
133
|
expect(t.skipped?).to eq true
|
134
134
|
end
|
135
|
-
|
135
|
+
|
136
136
|
it 'duration is calculated correctly' do
|
137
137
|
t = SimpleJUnit::TestCase.new('foo')
|
138
138
|
t.start
|
@@ -140,18 +140,17 @@ describe 'SimpleJUnit' do
|
|
140
140
|
t.finish
|
141
141
|
expect(t.duration.to_i).to eq 2
|
142
142
|
end
|
143
|
-
|
143
|
+
|
144
144
|
it 'generates correct XML' do
|
145
145
|
name = random_string(5)
|
146
146
|
type = random_string(7)
|
147
147
|
output = random_string(13)
|
148
148
|
error = random_string(11)
|
149
149
|
t = SimpleJUnit::TestCase.new(name)
|
150
|
-
t.
|
150
|
+
t.pass(output: output, error: error)
|
151
151
|
xml = t.to_s.gsub(/\n\s*/, '')
|
152
152
|
expect(xml).to match /<testcase classname="#{name}" time=""><system-out>#{output}<\/system-out><system-err>#{error}<\/system-err><\/testcase>/
|
153
153
|
end
|
154
154
|
end
|
155
155
|
end
|
156
156
|
|
157
|
-
|
data/spec/spec_helper.rb
CHANGED
@@ -102,187 +102,8 @@ RSpec.configure do |config|
|
|
102
102
|
=end
|
103
103
|
end
|
104
104
|
|
105
|
+
require 'file_generators'
|
106
|
+
|
105
107
|
def random_string(size=10)
|
106
108
|
(0..size).map { ('a'..'z').to_a[rand(26)] }.join
|
107
109
|
end
|
108
|
-
|
109
|
-
|
110
|
-
def generate_json(validity, extension: '.json')
|
111
|
-
filebase = random_string(16)
|
112
|
-
if validity == :valid
|
113
|
-
open(filebase + extension, 'w') do |fh|
|
114
|
-
fh.puts <<EOF
|
115
|
-
{
|
116
|
-
"test": "good JSON",
|
117
|
-
"foo": "bar"
|
118
|
-
}
|
119
|
-
EOF
|
120
|
-
end
|
121
|
-
elsif validity == :invalid
|
122
|
-
open(filebase + extension, 'w') do |fh|
|
123
|
-
fh.puts <<EOF
|
124
|
-
{
|
125
|
-
"test": "bad JSON"
|
126
|
-
"foo": "bar"
|
127
|
-
}
|
128
|
-
EOF
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
return filebase + extension
|
133
|
-
end
|
134
|
-
|
135
|
-
|
136
|
-
def generate_yaml(validity, extension: '.yaml')
|
137
|
-
filebase = random_string(16)
|
138
|
-
if validity == :valid
|
139
|
-
open(filebase + extension, 'w') do |fh|
|
140
|
-
fh.puts <<EOF
|
141
|
-
---
|
142
|
-
test: "good YAML"
|
143
|
-
foo: "bar"
|
144
|
-
EOF
|
145
|
-
end
|
146
|
-
elsif validity == :invalid
|
147
|
-
open(filebase + extension, 'w') do |fh|
|
148
|
-
fh.puts <<EOF
|
149
|
-
===
|
150
|
-
test: "bad YAML",
|
151
|
-
foo: "bar"
|
152
|
-
EOF
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
return filebase + extension
|
157
|
-
end
|
158
|
-
|
159
|
-
|
160
|
-
def generate_ruby(validity, extension: '.rb')
|
161
|
-
filebase = random_string(16)
|
162
|
-
if validity == :valid
|
163
|
-
open(filebase + extension, 'w') do |fh|
|
164
|
-
fh.puts <<EOF
|
165
|
-
#!/usr/bin/env ruby
|
166
|
-
puts "valid ruby!"
|
167
|
-
EOF
|
168
|
-
end
|
169
|
-
elsif validity == :invalid
|
170
|
-
open(filebase + extension, 'w') do |fh|
|
171
|
-
fh.puts <<EOF
|
172
|
-
#!/usr/bin/env ruby
|
173
|
-
put "invalid ruby!'
|
174
|
-
EOF
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
return filebase + extension
|
179
|
-
end
|
180
|
-
|
181
|
-
|
182
|
-
def generate_python(validity, extension: '.py')
|
183
|
-
filebase = random_string(16)
|
184
|
-
if validity == :valid
|
185
|
-
open(filebase + extension, 'w') do |fh|
|
186
|
-
fh.puts <<EOF
|
187
|
-
#!/usr/bin/env python
|
188
|
-
print("valid python!")
|
189
|
-
EOF
|
190
|
-
end
|
191
|
-
elsif validity == :invalid
|
192
|
-
open(filebase + extension, 'w') do |fh|
|
193
|
-
fh.puts <<EOF
|
194
|
-
#!/usr/bin/env python
|
195
|
-
print("invalid python!')
|
196
|
-
EOF
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
return filebase + extension
|
201
|
-
end
|
202
|
-
|
203
|
-
|
204
|
-
def generate_perl(validity, extension: '.pl')
|
205
|
-
filebase = random_string(16)
|
206
|
-
if validity == :valid
|
207
|
-
open(filebase + extension, 'w') do |fh|
|
208
|
-
fh.puts <<EOF
|
209
|
-
#!/usr/bin/env perl
|
210
|
-
print "valid ";
|
211
|
-
print "perl!"
|
212
|
-
EOF
|
213
|
-
end
|
214
|
-
elsif validity == :invalid
|
215
|
-
open(filebase + extension, 'w') do |fh|
|
216
|
-
fh.puts <<EOF
|
217
|
-
#!/usr/bin/env perl
|
218
|
-
print "invalid "
|
219
|
-
print "perl!"
|
220
|
-
EOF
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
return filebase + extension
|
225
|
-
end
|
226
|
-
|
227
|
-
|
228
|
-
def generate_bash(validity, extension: '.sh')
|
229
|
-
filebase = random_string(16)
|
230
|
-
if validity == :valid
|
231
|
-
open(filebase + extension, 'w') do |fh|
|
232
|
-
fh.puts <<EOF
|
233
|
-
#!/bin/bash
|
234
|
-
echo "valid shell!"
|
235
|
-
EOF
|
236
|
-
end
|
237
|
-
elsif validity == :invalid
|
238
|
-
open(filebase + extension, 'w') do |fh|
|
239
|
-
fh.puts <<EOF
|
240
|
-
#!/bin/bash
|
241
|
-
echo "invalid shell!'
|
242
|
-
EOF
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
return filebase + extension
|
247
|
-
end
|
248
|
-
|
249
|
-
|
250
|
-
def generate_erb(validity, extension: '.erb')
|
251
|
-
filebase = random_string(16)
|
252
|
-
if validity == :valid
|
253
|
-
open(filebase + extension, 'w') do |fh|
|
254
|
-
fh.puts <<EOF
|
255
|
-
<% puts "valid erb!" %>
|
256
|
-
EOF
|
257
|
-
end
|
258
|
-
elsif validity == :invalid
|
259
|
-
open(filebase + extension, 'w') do |fh|
|
260
|
-
fh.puts <<EOF
|
261
|
-
<% puts "invalid " <%= erb!" %>
|
262
|
-
EOF
|
263
|
-
end
|
264
|
-
end
|
265
|
-
|
266
|
-
return filebase + extension
|
267
|
-
end
|
268
|
-
|
269
|
-
|
270
|
-
def generate_puppet(validity, extension: '.pp')
|
271
|
-
filebase = random_string(16)
|
272
|
-
if validity == :valid
|
273
|
-
open(filebase + extension, 'w') do |fh|
|
274
|
-
fh.puts <<EOF
|
275
|
-
puppet { 'good': }
|
276
|
-
EOF
|
277
|
-
end
|
278
|
-
elsif validity == :invalid
|
279
|
-
open(filebase + extension, 'w') do |fh|
|
280
|
-
fh.puts <<EOF
|
281
|
-
puppet { "bad" }
|
282
|
-
EOF
|
283
|
-
end
|
284
|
-
end
|
285
|
-
|
286
|
-
return filebase + extension
|
287
|
-
end
|
288
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-ci-testing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.16.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerard Hickey
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: puppet
|
@@ -140,16 +140,16 @@ dependencies:
|
|
140
140
|
name: rake
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- - "
|
143
|
+
- - ">="
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
145
|
+
version: 12.3.3
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
|
-
- - "
|
150
|
+
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version:
|
152
|
+
version: 12.3.3
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: rspec
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -207,12 +207,13 @@ files:
|
|
207
207
|
- lib/check_file_syntax.rb
|
208
208
|
- lib/simple_junit.rb
|
209
209
|
- spec/check_file_syntax_spec.rb
|
210
|
+
- spec/file_generators.rb
|
210
211
|
- spec/simple_junit_spec.rb
|
211
212
|
- spec/spec_helper.rb
|
212
|
-
homepage: https://
|
213
|
+
homepage: https://gitlab.com/wt0f/puppet-ci-testing/
|
213
214
|
licenses: []
|
214
215
|
metadata: {}
|
215
|
-
post_install_message:
|
216
|
+
post_install_message:
|
216
217
|
rdoc_options: []
|
217
218
|
require_paths:
|
218
219
|
- lib
|
@@ -227,9 +228,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
227
228
|
- !ruby/object:Gem::Version
|
228
229
|
version: '0'
|
229
230
|
requirements: []
|
230
|
-
|
231
|
-
|
232
|
-
signing_key:
|
231
|
+
rubygems_version: 3.0.8
|
232
|
+
signing_key:
|
233
233
|
specification_version: 4
|
234
234
|
summary: Utilities to perform Puppet testing in a CI workflow
|
235
235
|
test_files: []
|