puppet-ci-testing 0.16.0 → 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 +4 -4
- data/bin/check_file_syntax +3 -3
- data/lib/check_file_syntax.rb +35 -29
- data/lib/simple_junit.rb +2 -2
- data/spec/simple_junit_spec.rb +36 -37
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
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
@@ -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
@@ -29,8 +29,7 @@ end
|
|
29
29
|
|
30
30
|
module CheckFileSyntax
|
31
31
|
|
32
|
-
ALL_CHECKS = [:puppet, :ruby, :python, :perl, :bash, :erb, :yaml, :json
|
33
|
-
:gitlab_ci]
|
32
|
+
ALL_CHECKS = [:puppet, :ruby, :python, :perl, :bash, :erb, :yaml, :json]
|
34
33
|
|
35
34
|
module_function
|
36
35
|
def type_of_file(path, interpreter, extensions)
|
@@ -178,35 +177,42 @@ module CheckFileSyntax
|
|
178
177
|
elsif gitlab_ci_file? path
|
179
178
|
ci_content = YAML.load_file(path)
|
180
179
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
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
|
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]
|
208
188
|
end
|
209
189
|
end
|
190
|
+
|
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
|
+
|
210
216
|
elsif json_file? path
|
211
217
|
begin
|
212
218
|
JSON.parse(File.read(path))
|
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?
|
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
|
-
|
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.16.
|
4
|
+
version: 0.16.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerard Hickey
|
8
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
|