gridium 1.0.17 → 1.0.18
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/docker-compose.yml +4 -0
- data/lib/testrail.rb +121 -91
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0b267c861928652d286605296c289c05834430a
|
4
|
+
data.tar.gz: a778ba115b547531c36de17ef519468e94915dcf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 533b3a7724808ff449f8218f2764393e98e387df614ba91d135712947b81959a0c7f188ecd7da43935f09439820e0709fd160548adc932c7068238e632c1b6a9
|
7
|
+
data.tar.gz: 766c008f362c7c8d2df085f343b536538041538fc46a4911fd7523dea742cb14043e2522dda7e86741a20e143d6d0a46597b9a6ee580d4fdfa88320eaf8c6856
|
data/docker-compose.yml
CHANGED
@@ -21,5 +21,9 @@ services:
|
|
21
21
|
- S3_SECRET_ACCESS_KEY=$S3_SECRET_ACCESS_KEY
|
22
22
|
- S3_DEFAULT_REGION=$S3_DEFAULT_REGION
|
23
23
|
- S3_ROOT_BUCKET=$S3_ROOT_BUCKET
|
24
|
+
- GRIDIUM_TR_PID=$GRIDIUM_TR_PID
|
25
|
+
- GRIDIUM_TR_PW=$GRIDIUM_TR_PW
|
26
|
+
- GRIDIUM_TR_URL=$GRIDIUM_TR_URL
|
27
|
+
- GRIDIUM_TR_USER=$GRIDIUM_TR_USER
|
24
28
|
- BUILD_NUMBER=$BUILD_NUMBER
|
25
29
|
command: "tail -f /dev/null"
|
data/lib/testrail.rb
CHANGED
@@ -4,120 +4,150 @@ require 'uri'
|
|
4
4
|
require 'json'
|
5
5
|
|
6
6
|
module Gridium
|
7
|
-
|
8
|
-
|
7
|
+
class TestRail
|
8
|
+
ENV_ERROR = "Environment Variable not set!"
|
9
|
+
CONFIG = {:pass => 1, :blocked => 2, :untested => 3, :retest => 4, :fail => 5}.freeze
|
9
10
|
|
10
|
-
#TestRail Statuses
|
11
|
-
PASSED = 1
|
12
|
-
BLOCKED = 2
|
13
|
-
UNTESTED = 3
|
14
|
-
RETEST = 4
|
15
|
-
FAILED = 5
|
16
11
|
|
17
|
-
|
12
|
+
def initialize
|
18
13
|
if Gridium.config.testrail
|
19
14
|
@url = ENV['GRIDIUM_TR_URL'].empty? || ENV['GRIDIUM_TR_URL'].nil? ? ENV_ERROR : ENV['GRIDIUM_TR_URL'] + '/index.php?/api/v2/'
|
20
15
|
@user = ENV['GRIDIUM_TR_USER'].empty? || ENV['GRIDIUM_TR_USER'].nil? ? ENV_ERROR : ENV['GRIDIUM_TR_USER']
|
21
16
|
@password = ENV['GRIDIUM_TR_PW'].empty? || ENV['GRIDIUM_TR_PW'].nil? ? ENV_ERROR : ENV['GRIDIUM_TR_PW']
|
22
17
|
@pid = ENV['GRIDIUM_TR_PID'].empty? || ENV['GRIDIUM_TR_PID'].nil? ? ENV_ERROR : ENV['GRIDIUM_TR_PID']
|
23
|
-
|
24
|
-
|
18
|
+
@retry_attempts = 5
|
19
|
+
@time_between_retries = 3
|
20
|
+
@tc_results = Array.new
|
21
|
+
@tc_ids = Array.new
|
25
22
|
end
|
26
|
-
|
23
|
+
@run_info = {:id => 0 ,:error => false, :include_all => false}
|
24
|
+
end
|
27
25
|
|
26
|
+
# Creates a new test Run in your TestRail instance.
|
27
|
+
#
|
28
|
+
# @param name [String] the name of the test run. Error text will be added if an error occurs
|
29
|
+
# @param desc [String] a description of the run being added. Error text will be added if an error occurs
|
30
|
+
# @return [int] The run ID of the created run or zero if no run created.
|
28
31
|
def add_run(name, desc)
|
29
32
|
if Gridium.config.testrail
|
30
33
|
Log.debug("[GRIDIUM::TestRail] Creating Test Run: name: #{name} desc: #{desc}")
|
31
34
|
if name.nil? || name.empty? then
|
32
|
-
|
35
|
+
@run_info[:error] = true
|
36
|
+
else
|
37
|
+
@run_info[:name] = name
|
38
|
+
@run_info[:desc] = desc
|
33
39
|
end
|
34
|
-
r = _send_request('POST', "add_run/#{@pid}",
|
35
|
-
|
36
|
-
|
37
|
-
|
40
|
+
r = _send_request('POST', "#{@url}add_run/#{@pid}", @run_info)
|
41
|
+
if r.key?('error') || r["id"].nil?
|
42
|
+
@run_info[:error] = true
|
43
|
+
else
|
44
|
+
@run_info[:id] = r["id"]
|
45
|
+
Log.debug("[GRIDIUM::TestRail] Run Added: #{r}")
|
38
46
|
end
|
39
47
|
end
|
48
|
+
return @run_info[:id]
|
40
49
|
end
|
41
50
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
51
|
+
# Adds determines what the result of the test is and adds information to various arrays for processing during closing.
|
52
|
+
#
|
53
|
+
# @param rspec_test [RSpec::Example] the example provided by RSpec
|
54
|
+
# @return [bool] determine if case was added or not
|
55
|
+
def add_case(rspec_test)
|
56
|
+
added = false
|
57
|
+
if Gridium.config.testrail
|
58
|
+
Log.debug("[GRIDIUM::TestRail] Adding to list of TestRail Cases...")
|
59
|
+
if rspec_test.nil? then
|
60
|
+
Log.error("[GRIDIUM::TestRail] No test added to results. Turn of Gridium.config.testrail\n")
|
61
|
+
end
|
62
|
+
if rspec_test.exception
|
63
|
+
status = CONFIG[:fail]
|
64
|
+
message = rspec_test.exception.message
|
65
|
+
else
|
66
|
+
status = CONFIG[:pass]
|
67
|
+
message = 'Test Passed.'
|
68
|
+
end
|
69
|
+
test_info = {:case_id => rspec_test.metadata[:testrail_id], :status_id => status, :comment => message}
|
70
|
+
@tc_results.push(test_info)
|
71
|
+
@tc_ids.push(test_info[:case_id])
|
72
|
+
added = true
|
73
|
+
end
|
74
|
+
return added
|
75
|
+
end
|
60
76
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
77
|
+
# Updates the existing test run with test cases and results. Adds error text for missing test cases if needed. Closes the run as long as it exists.
|
78
|
+
#
|
79
|
+
# @return [bool] if the run was closed or not
|
80
|
+
def close_run
|
81
|
+
closed = false
|
82
|
+
if Gridium.config.testrail && !@run_info[:error]
|
83
|
+
Log.debug("[GRIDIUM::TestRail] Closing test runid: #{@run_info[:id]}\n")
|
84
|
+
r = _send_request('POST', "#{@url}update_run/#{@run_info[:id]}", {:case_ids => @tc_ids})
|
85
|
+
Log.debug("[GRIDIUM::TestRail] UPDATE RUN: #{r}")
|
86
|
+
sleep 0.25
|
87
|
+
r = _send_request('POST', "#{@url}add_results_for_cases/#{@run_info[:id]}", {results: @tc_results})
|
88
|
+
Log.debug("[GRIDIUM::TestRail] ADD RESULTS: #{r}")
|
89
|
+
sleep 0.25
|
90
|
+
Log.debug("#{r.class}")
|
91
|
+
if r.is_a?(Hash)
|
92
|
+
r = _send_request('POST', "#{@url}update_run/#{@run_info[:id]}", {:name => "ER:#{@run_info[:name]}", :description => "#{@run_info[:desc]}\nThe following was returned when adding cases: #{r}"})
|
93
|
+
Log.warn("[GRIDIUM::TestRail] ERROR: #{r}")
|
94
|
+
sleep 0.25
|
95
|
+
end
|
96
|
+
r = _send_request('POST', "#{@url}close_run/#{@run_info[:id]}", nil)
|
97
|
+
Log.debug("[GRIDIUM::TestRail] CLOSE RUN: #{r}")
|
98
|
+
closed = true
|
99
|
+
end
|
100
|
+
return closed
|
101
|
+
end
|
79
102
|
|
80
103
|
private
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
conn = Net::HTTP.new(url.host, url.port)
|
94
|
-
if url.scheme == 'https'
|
95
|
-
conn.use_ssl = true
|
96
|
-
conn.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
97
|
-
end
|
98
|
-
response = conn.request(request)
|
99
|
-
if response.body && !response.body.empty?
|
100
|
-
result = JSON.parse(response.body)
|
101
|
-
else
|
102
|
-
result = {}
|
103
|
-
end
|
104
|
+
def _send_request(method, uri, data)
|
105
|
+
attempts = @retry_attempts
|
106
|
+
url = URI.parse(uri)
|
107
|
+
Log.debug("[GRIDIUM::TestRail] Method: #{method} URL:#{uri} Data:#{data}")
|
108
|
+
if method == 'POST'
|
109
|
+
request = Net::HTTP::Post.new(url.path + '?' + url.query)
|
110
|
+
request.body = JSON.dump(data)
|
111
|
+
else
|
112
|
+
request = Net::HTTP::Get.new(url.path + '?' + url.query)
|
113
|
+
end
|
114
|
+
request.basic_auth(@user, @password)
|
115
|
+
request.add_field('Content-Type', 'application/json')
|
104
116
|
|
105
|
-
|
117
|
+
conn = Net::HTTP.new(url.host, url.port)
|
118
|
+
if url.scheme == 'https'
|
119
|
+
conn.use_ssl = true
|
120
|
+
conn.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
121
|
+
end
|
122
|
+
begin
|
123
|
+
response = conn.request(request)
|
124
|
+
if response.body && !response.body.empty?
|
125
|
+
result = JSON.parse(response.body)
|
126
|
+
else
|
127
|
+
result = {}
|
128
|
+
end
|
106
129
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
130
|
+
if response.code != '200'
|
131
|
+
if result && result.key?('error')
|
132
|
+
error = '"' + result['error'] + '"'
|
133
|
+
else
|
134
|
+
error = 'No additional error message received'
|
135
|
+
end
|
136
|
+
Log.error("[GRIDIUM::TestRail] #{response.code} - Error with request: #{error}")
|
137
|
+
end
|
138
|
+
rescue SocketError => error
|
139
|
+
Log.warn("[GRIDIUM::TestRail] SocketError - Retrying....")
|
140
|
+
if attempts > 0
|
141
|
+
attempts -= 1
|
142
|
+
sleep @time_between_retries
|
143
|
+
retry
|
144
|
+
end
|
145
|
+
Log.error("[GRIDIUM::TestRail] Socket Error after numerous attempts. Error: #{error}")
|
146
|
+
result = {error: "SocketError after #{@retry_attempts} attempts. See Error Log."}
|
147
|
+
end
|
116
148
|
|
117
|
-
|
118
|
-
|
119
|
-
|
149
|
+
result
|
150
|
+
end
|
151
|
+
end
|
120
152
|
|
121
|
-
class APIError < StandardError
|
122
|
-
end
|
123
153
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gridium
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Seth Urban
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|