puppet-ci-testing 0.15.0 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/check_file_syntax +6 -6
- data/lib/check_file_syntax.rb +71 -17
- data/spec/check_file_syntax_spec.rb +44 -27
- data/spec/file_generators.rb +211 -0
- data/spec/spec_helper.rb +2 -181
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 928347f53049919abab4494bef43d7181e015b598b6bbae4688e42070ed498b8
|
4
|
+
data.tar.gz: 379237a85a0ae3c4ef5549c109e84ee69b39df18b5574af3bd04077676d854b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3fc973af4473990e3397fad7ec2d0af3230244a2ecd578b5d3260866cd74740b9951f8fac35d97505ef84789b8bf608d9274c2ced1293a54a364083a162193f3
|
7
|
+
data.tar.gz: 862541f3915b9e0ea356af25abf8442af5342d77b1c9b3c722764bf40e38ee83baf04f12b839934fa1513f4f6b48f25ed5adefa7bc4897928b50a28b06b5c68f
|
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
|
data/lib/check_file_syntax.rb
CHANGED
@@ -2,11 +2,35 @@ 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
|
|
9
|
-
ALL_CHECKS = [:puppet, :ruby, :python, :perl, :bash, :erb, :yaml, :json
|
32
|
+
ALL_CHECKS = [:puppet, :ruby, :python, :perl, :bash, :erb, :yaml, :json,
|
33
|
+
:gitlab_ci]
|
10
34
|
|
11
35
|
module_function
|
12
36
|
def type_of_file(path, interpreter, extensions)
|
@@ -57,6 +81,9 @@ module CheckFileSyntax
|
|
57
81
|
type_of_file(path, '---', ['.yaml', '.yml'])
|
58
82
|
end
|
59
83
|
|
84
|
+
def gitlab_ci_file?(path)
|
85
|
+
type_of_file(path, :gitlab_ci, '.gitlab-ci.yml')
|
86
|
+
end
|
60
87
|
|
61
88
|
module_function
|
62
89
|
def show_status (name, success, errors)
|
@@ -116,14 +143,12 @@ module CheckFileSyntax
|
|
116
143
|
puts 'Consider installing puppet so that syntax can be checked.'.colorize(:yellow)
|
117
144
|
status = :skipped
|
118
145
|
end
|
119
|
-
end
|
120
146
|
|
121
|
-
|
147
|
+
elsif erb_file? path
|
122
148
|
errors = `cat #{path} | erb -x -T - | ruby -c 2>&1`
|
123
149
|
status = $?.success? ? :passed : :failed
|
124
|
-
end
|
125
150
|
|
126
|
-
|
151
|
+
elsif python_file? path
|
127
152
|
if system('which python >/dev/null')
|
128
153
|
errors = `python -m py_compile #{path} 2>&1`
|
129
154
|
status = $?.success? ? :passed : :failed
|
@@ -131,14 +156,12 @@ module CheckFileSyntax
|
|
131
156
|
puts 'Consider installing python so that syntax can be checked.'.colorize(:yellow)
|
132
157
|
status = :skipped
|
133
158
|
end
|
134
|
-
end
|
135
159
|
|
136
|
-
|
160
|
+
elsif ruby_file? path
|
137
161
|
errors = `ruby -c #{path} 2>&1`
|
138
162
|
status = $?.success? ? :passed : :failed
|
139
|
-
end
|
140
163
|
|
141
|
-
|
164
|
+
elsif perl_file? path
|
142
165
|
if system('which perl >/dev/null')
|
143
166
|
errors = `perl -c #{path} 2>&1`
|
144
167
|
status = $?.success? ? :passed : :failed
|
@@ -146,15 +169,45 @@ module CheckFileSyntax
|
|
146
169
|
puts 'Consider installing perl so that syntax can be checked.'.colorize(:yellow)
|
147
170
|
status = :skipped
|
148
171
|
end
|
149
|
-
end
|
150
172
|
|
151
|
-
|
173
|
+
elsif bash_file? path
|
152
174
|
errors = `bash -n #{path} 2>&1`.to_i
|
153
175
|
status = $?.success? ? :passed : :failed
|
154
|
-
end
|
155
176
|
|
156
|
-
|
157
|
-
|
177
|
+
# GitLab CI files need to be processed before YAML
|
178
|
+
elsif gitlab_ci_file? path
|
179
|
+
ci_content = YAML.load_file(path)
|
180
|
+
|
181
|
+
token_file = ENV['CI_LINT_TOKEN'] || "#{Dir.home}/.gitlab-tokens"
|
182
|
+
if File.readable?(token_file)
|
183
|
+
tokens = YAML.load_file(token_file)
|
184
|
+
# Any token should work
|
185
|
+
priv_token = tokens.values()[0]
|
186
|
+
|
187
|
+
begin
|
188
|
+
uri = URI.parse('https://gitlab.com/api/v4/ci/lint')
|
189
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
190
|
+
http.use_ssl = true
|
191
|
+
#Net::HTTP.enable_debug!
|
192
|
+
request = Net::HTTP::Post.new(uri.path, {
|
193
|
+
'Content-Type' => 'application/json',
|
194
|
+
'Accept' => 'application/json',
|
195
|
+
'PRIVATE-TOKEN' => 'ShgK6TXXENFtKA5RWC8U'
|
196
|
+
})
|
197
|
+
request.body = {content: ci_content.to_json}.to_json
|
198
|
+
response = http.request(request)
|
199
|
+
rescue => e
|
200
|
+
puts "Exception: #{e}"
|
201
|
+
end
|
202
|
+
results = JSON.parse(response.body)
|
203
|
+
case results['status']
|
204
|
+
when 'valid'
|
205
|
+
status = :passed
|
206
|
+
when 'invalid'
|
207
|
+
status = :failed
|
208
|
+
end
|
209
|
+
end
|
210
|
+
elsif json_file? path
|
158
211
|
begin
|
159
212
|
JSON.parse(File.read(path))
|
160
213
|
status = :passed
|
@@ -162,9 +215,8 @@ module CheckFileSyntax
|
|
162
215
|
errors = e.message
|
163
216
|
status = :failed
|
164
217
|
end
|
165
|
-
end
|
166
218
|
|
167
|
-
|
219
|
+
elsif yaml_file? path
|
168
220
|
begin
|
169
221
|
YAML.parse(File.read(path))
|
170
222
|
status = :passed
|
@@ -181,4 +233,6 @@ module CheckFileSyntax
|
|
181
233
|
error_count += 1 if status == :failed
|
182
234
|
end
|
183
235
|
end
|
184
|
-
end
|
236
|
+
end
|
237
|
+
|
238
|
+
|
@@ -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/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.0
|
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: 2021-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: puppet
|
@@ -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,8 +228,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
227
228
|
- !ruby/object:Gem::Version
|
228
229
|
version: '0'
|
229
230
|
requirements: []
|
230
|
-
rubygems_version: 3.0.
|
231
|
-
signing_key:
|
231
|
+
rubygems_version: 3.0.8
|
232
|
+
signing_key:
|
232
233
|
specification_version: 4
|
233
234
|
summary: Utilities to perform Puppet testing in a CI workflow
|
234
235
|
test_files: []
|