gridium 1.0.17 → 1.0.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/docker-compose.yml +4 -0
  3. data/lib/testrail.rb +121 -91
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a2308c591e8510889e1757c6ba7a3d06cda13676
4
- data.tar.gz: 1d2b86fcc8e680a7c8c34209a40188333d6096a0
3
+ metadata.gz: c0b267c861928652d286605296c289c05834430a
4
+ data.tar.gz: a778ba115b547531c36de17ef519468e94915dcf
5
5
  SHA512:
6
- metadata.gz: d85b1f0c1e566f810afa8f95ab969174210fbf8e33b31507a73cdd72c316594d241821c139d25219242b4499433077248df8e794ed9a47b4262633a9b8f46351
7
- data.tar.gz: b2072f20624c7ac16f0e8b0991068243f0d05db665015ba21dd20c9ecc9c3da5c00f185ec460952f4e9b9a40463eaf50676a4791be40a81a1c552b8f4113c64a
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
- class TestRail
8
- ENV_ERROR = "Environment Variable not set!"
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
- def initialize
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
- @testcase_ids = Array.new
24
- @testcase_infos = Array.new
18
+ @retry_attempts = 5
19
+ @time_between_retries = 3
20
+ @tc_results = Array.new
21
+ @tc_ids = Array.new
25
22
  end
26
- end
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
- raise(ArgumentError, "Empty Run Name - Run name is required")
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}", {:name => name, :description => desc, :include_all => false})
35
- Log.debug("Result: #{r}")
36
- unless r["id"].nil?
37
- @runid = r["id"]
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
- def add_case(rspec_test)
43
- if Gridium.config.testrail
44
- Log.debug("[GRIDIUM::TestRail] Adding to list of TestRail Cases...")
45
- if rspec_test.nil? then
46
- Log.error("[GRIDIUM::TestRail] No test added to results. Turn of Gridium.config.testrail\n")
47
- end
48
- if rspec_test.exception
49
- status = FAILED
50
- message = rspec_test.exception.message
51
- else
52
- status = PASSED
53
- message = 'Test Passed.'
54
- end
55
- test_info = {:trid => rspec_test.metadata[:testrail_id], :status_id => status, :message => message}
56
- @testcase_infos.push(test_info)
57
- @testcase_ids.push(test_info[:trid])
58
- end
59
- end
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
- def close_run
62
- if Gridium.config.testrail
63
- Log.debug("[GRIDIUM::TestRail] Closing test runid: #{@runid}\n")
64
- unless @runid.nil?
65
- r = _send_request('POST', "update_run/#{@runid}", {:case_ids => @testcase_ids})
66
- @testcase_infos.each do |tc|
67
- r = _send_request(
68
- 'POST',
69
- "add_result_for_case/#{@runid}/#{tc[:trid]}",
70
- status_id: tc[:status_id],
71
- comment: tc[:message]
72
- )
73
- sleep(0.25)
74
- end
75
- r = _send_request('POST', "close_run/#{@runid}", nil)
76
- end
77
- end
78
- end
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
- def _send_request(method, uri, data)
82
- url = URI.parse(@url + uri)
83
- Log.debug("[GRIDIUM::TestRail] Method: #{method} URL:#{uri} Data:#{data}")
84
- if method == 'POST'
85
- request = Net::HTTP::Post.new(url.path + '?' + url.query)
86
- request.body = JSON.dump(data)
87
- else
88
- request = Net::HTTP::Get.new(url.path + '?' + url.query)
89
- end
90
- request.basic_auth(@user, @password)
91
- request.add_field('Content-Type', 'application/json')
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
- if response.code != '200'
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
- if result && result.key?('error')
108
- error = '"' + result['error'] + '"'
109
- else
110
- error = 'No additional error message received'
111
- end
112
- Log.debug("[GRIDIUM::TestRail] Error with request: #{error}")
113
- raise APIError.new('TestRail API returned HTTP %s (%s)' %
114
- [response.code, error])
115
- end
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
- result
118
- end
119
- end
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.17
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-24 00:00:00.000000000 Z
11
+ date: 2017-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler