bugsnag-maze-runner 7.22.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/bugsnag-print-load-paths +6 -0
- data/bin/download-logs +74 -0
- data/bin/maze-runner +174 -0
- data/bin/upload-app +56 -0
- data/lib/features/scripts/await-android-emulator.sh +11 -0
- data/lib/features/scripts/clear-android-app-data.sh +8 -0
- data/lib/features/scripts/force-stop-android-app.sh +8 -0
- data/lib/features/scripts/install-android-app.sh +15 -0
- data/lib/features/scripts/launch-android-app.sh +38 -0
- data/lib/features/scripts/launch-android-emulator.sh +15 -0
- data/lib/features/steps/android_steps.rb +51 -0
- data/lib/features/steps/app_automator_steps.rb +228 -0
- data/lib/features/steps/aws_sam_steps.rb +212 -0
- data/lib/features/steps/breadcrumb_steps.rb +80 -0
- data/lib/features/steps/browser_steps.rb +93 -0
- data/lib/features/steps/build_api_steps.rb +25 -0
- data/lib/features/steps/document_server_steps.rb +7 -0
- data/lib/features/steps/error_reporting_steps.rb +358 -0
- data/lib/features/steps/feature_flag_steps.rb +190 -0
- data/lib/features/steps/header_steps.rb +72 -0
- data/lib/features/steps/log_steps.rb +29 -0
- data/lib/features/steps/multipart_request_steps.rb +142 -0
- data/lib/features/steps/network_steps.rb +135 -0
- data/lib/features/steps/payload_steps.rb +257 -0
- data/lib/features/steps/proxy_steps.rb +34 -0
- data/lib/features/steps/query_parameter_steps.rb +31 -0
- data/lib/features/steps/request_assertion_steps.rb +186 -0
- data/lib/features/steps/runner_steps.rb +428 -0
- data/lib/features/steps/session_tracking_steps.rb +116 -0
- data/lib/features/steps/trace_steps.rb +206 -0
- data/lib/features/steps/value_steps.rb +119 -0
- data/lib/features/support/env.rb +7 -0
- data/lib/features/support/internal_hooks.rb +207 -0
- data/lib/maze/api/appium/file_manager.rb +29 -0
- data/lib/maze/appium_server.rb +112 -0
- data/lib/maze/assertions/request_set_assertions.rb +97 -0
- data/lib/maze/aws/sam.rb +112 -0
- data/lib/maze/aws_public_ip.rb +53 -0
- data/lib/maze/bugsnag_config.rb +42 -0
- data/lib/maze/checks/assert_check.rb +69 -0
- data/lib/maze/checks/noop_check.rb +34 -0
- data/lib/maze/client/appium/base_client.rb +131 -0
- data/lib/maze/client/appium/bb_client.rb +102 -0
- data/lib/maze/client/appium/bb_devices.rb +127 -0
- data/lib/maze/client/appium/bs_client.rb +91 -0
- data/lib/maze/client/appium/bs_devices.rb +141 -0
- data/lib/maze/client/appium/bs_legacy_client.rb +31 -0
- data/lib/maze/client/appium/local_client.rb +67 -0
- data/lib/maze/client/appium.rb +23 -0
- data/lib/maze/client/bb_api_client.rb +102 -0
- data/lib/maze/client/bb_client_utils.rb +181 -0
- data/lib/maze/client/bs_client_utils.rb +168 -0
- data/lib/maze/client/selenium/base_client.rb +15 -0
- data/lib/maze/client/selenium/bb_browsers.yml +188 -0
- data/lib/maze/client/selenium/bb_client.rb +38 -0
- data/lib/maze/client/selenium/bs_browsers.yml +257 -0
- data/lib/maze/client/selenium/bs_client.rb +89 -0
- data/lib/maze/client/selenium/local_client.rb +16 -0
- data/lib/maze/client/selenium.rb +16 -0
- data/lib/maze/compare.rb +161 -0
- data/lib/maze/configuration.rb +182 -0
- data/lib/maze/docker.rb +147 -0
- data/lib/maze/document_server.rb +46 -0
- data/lib/maze/driver/appium.rb +198 -0
- data/lib/maze/driver/browser.rb +124 -0
- data/lib/maze/errors.rb +52 -0
- data/lib/maze/generator.rb +55 -0
- data/lib/maze/helper.rb +122 -0
- data/lib/maze/hooks/appium_hooks.rb +55 -0
- data/lib/maze/hooks/browser_hooks.rb +15 -0
- data/lib/maze/hooks/command_hooks.rb +9 -0
- data/lib/maze/hooks/error_code_hook.rb +49 -0
- data/lib/maze/hooks/hooks.rb +61 -0
- data/lib/maze/http_request.rb +21 -0
- data/lib/maze/interactive_cli.rb +173 -0
- data/lib/maze/logger.rb +86 -0
- data/lib/maze/macos_utils.rb +14 -0
- data/lib/maze/maze_output.rb +88 -0
- data/lib/maze/network.rb +49 -0
- data/lib/maze/option/parser.rb +240 -0
- data/lib/maze/option/processor.rb +130 -0
- data/lib/maze/option/validator.rb +155 -0
- data/lib/maze/option.rb +62 -0
- data/lib/maze/plugins/bugsnag_reporting_plugin.rb +49 -0
- data/lib/maze/plugins/cucumber_report_plugin.rb +101 -0
- data/lib/maze/plugins/error_code_plugin.rb +21 -0
- data/lib/maze/plugins/global_retry_plugin.rb +38 -0
- data/lib/maze/proxy.rb +114 -0
- data/lib/maze/request_list.rb +87 -0
- data/lib/maze/request_repeater.rb +49 -0
- data/lib/maze/retry_handler.rb +67 -0
- data/lib/maze/runner.rb +149 -0
- data/lib/maze/schemas/OtelTraceSchema.json +390 -0
- data/lib/maze/schemas/trace_schema.rb +7 -0
- data/lib/maze/schemas/trace_validator.rb +98 -0
- data/lib/maze/server.rb +251 -0
- data/lib/maze/servlets/base_servlet.rb +27 -0
- data/lib/maze/servlets/command_servlet.rb +47 -0
- data/lib/maze/servlets/log_servlet.rb +64 -0
- data/lib/maze/servlets/reflective_servlet.rb +70 -0
- data/lib/maze/servlets/servlet.rb +199 -0
- data/lib/maze/servlets/temp.rb +0 -0
- data/lib/maze/servlets/trace_servlet.rb +13 -0
- data/lib/maze/store.rb +15 -0
- data/lib/maze/terminating_server.rb +129 -0
- data/lib/maze/timers.rb +51 -0
- data/lib/maze/wait.rb +35 -0
- data/lib/maze.rb +27 -0
- data/lib/utils/deep_merge.rb +17 -0
- data/lib/utils/selenium_money_patch.rb +17 -0
- metadata +451 -0
@@ -0,0 +1,186 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'open-uri'
|
5
|
+
require 'json'
|
6
|
+
require 'cgi'
|
7
|
+
require_relative '../../maze/wait'
|
8
|
+
|
9
|
+
# @!group Request assertion steps
|
10
|
+
|
11
|
+
def assert_received_requests(request_count, list, list_name, precise = true)
|
12
|
+
timeout = Maze.config.receive_requests_wait
|
13
|
+
wait = Maze::Wait.new(timeout: timeout)
|
14
|
+
|
15
|
+
received = wait.until { list.size_remaining >= request_count }
|
16
|
+
|
17
|
+
unless received
|
18
|
+
raise Test::Unit::AssertionFailedError.new <<-MESSAGE
|
19
|
+
Expected #{request_count} #{list_name} but received #{list.size_remaining} within the #{timeout}s timeout.
|
20
|
+
This could indicate that:
|
21
|
+
- Bugsnag crashed with a fatal error.
|
22
|
+
- Bugsnag did not make the requests that it should have done.
|
23
|
+
- The requests were made, but not deemed to be valid (e.g. missing integrity header).
|
24
|
+
- The requests made were prevented from being received due to a network or other infrastructure issue.
|
25
|
+
Please check the Maze Runner and device logs to confirm.)
|
26
|
+
MESSAGE
|
27
|
+
end
|
28
|
+
|
29
|
+
if precise
|
30
|
+
Maze.check.equal(request_count, list.size_remaining, "#{list.size_remaining} #{list_name} received")
|
31
|
+
else
|
32
|
+
Maze.check.operator(request_count, :<=, list.size_remaining, "#{list.size_remaining} #{list_name} received")
|
33
|
+
end
|
34
|
+
|
35
|
+
verify_schema_matches(list, list_name)
|
36
|
+
validate_payload_elements(list, list_name)
|
37
|
+
end
|
38
|
+
|
39
|
+
def verify_schema_matches(list, list_name)
|
40
|
+
request_schema_results = list.all.map { |request| request[:schema_errors] }
|
41
|
+
passed = true
|
42
|
+
request_schema_results.each.with_index(1) do |schema_errors, index|
|
43
|
+
next if schema_errors.nil?
|
44
|
+
if schema_errors.size > 0
|
45
|
+
passed = false
|
46
|
+
$stdout.puts "\n"
|
47
|
+
$stdout.puts "\e[31m--- #{list_name} #{index} failed validation with errors at the following locations:\e[0m"
|
48
|
+
schema_errors.each do |error|
|
49
|
+
$stdout.puts "\e[31m#{error["data_pointer"]} failed to match #{error["schema_pointer"]}\e[0m"
|
50
|
+
end
|
51
|
+
$stdout.puts "\n"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
unless passed
|
56
|
+
raise Test::Unit::AssertionFailedError.new 'The received payloads did not match the endpoint schema. A full list of the errors can be found above'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def validate_payload_elements(list, list_name)
|
61
|
+
validator_class = case list_name
|
62
|
+
when 'trace', 'traces'
|
63
|
+
Maze::Schemas::TraceValidator
|
64
|
+
else
|
65
|
+
nil
|
66
|
+
end
|
67
|
+
|
68
|
+
if validator_class
|
69
|
+
validators = list.all.map do |request|
|
70
|
+
validator = validator_class.new(request[:body])
|
71
|
+
validator.validate
|
72
|
+
validator
|
73
|
+
end
|
74
|
+
|
75
|
+
return if validators.all? { |validator| validator.success }
|
76
|
+
validators.each.with_index(1) do |validator, index|
|
77
|
+
unless validator.success
|
78
|
+
$stdout.puts "\n"
|
79
|
+
$stdout.puts "\e[31m--- #{list_name} #{index} failed validation with the following errors:\e[0m"
|
80
|
+
validator.errors.each do |error|
|
81
|
+
$stdout.puts "\e[31m#{error}\e[0m"
|
82
|
+
end
|
83
|
+
$stdout.puts "\n"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
raise Test::Unit::AssertionFailedError.new("One or more #{list_name} payloads failed validation. A full list of the errors can be found above")
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
#
|
91
|
+
# Error request assertions
|
92
|
+
#
|
93
|
+
# Shortcut to waiting to receive a single request of the given type
|
94
|
+
#
|
95
|
+
# @step_input request_type [String] The type of request (error, session, build, etc)
|
96
|
+
Then('I wait to receive a(n) {word}') do |request_type|
|
97
|
+
step "I wait to receive 1 #{request_type}"
|
98
|
+
end
|
99
|
+
|
100
|
+
# Continually checks to see if the required amount of requests have been received,
|
101
|
+
# timing out according to @see Maze.config.receive_requests_wait.
|
102
|
+
# If all expected requests are received and have the Bugsnag-Sent-At header, they
|
103
|
+
# will be sorted by the header.
|
104
|
+
#
|
105
|
+
# @step_input request_type [String] The type of request (error, session, build, etc)
|
106
|
+
# @step_input request_count [Integer] The amount of requests expected
|
107
|
+
Then('I wait to receive {int} {word}') do |request_count, request_type|
|
108
|
+
list = Maze::Server.list_for(request_type)
|
109
|
+
assert_received_requests request_count, list, request_type
|
110
|
+
list.sort_by_sent_at! request_count
|
111
|
+
end
|
112
|
+
|
113
|
+
# Continually checks to see if at least the number requests given has been received,
|
114
|
+
# timing out according to @see Maze.config.receive_requests_wait.
|
115
|
+
#
|
116
|
+
# This step can tolerate receiving more than the expected number of requests.
|
117
|
+
#
|
118
|
+
# @step_input request_type [String] The type of request (error, session, build, etc)
|
119
|
+
# @step_input request_count [Integer] The amount of requests expected
|
120
|
+
Then('I wait to receive at least {int} {word}') do |request_count, request_type|
|
121
|
+
list = Maze::Server.list_for(request_type)
|
122
|
+
assert_received_requests request_count, list, request_type, false
|
123
|
+
end
|
124
|
+
|
125
|
+
# Sorts the remaining requests in a list by the field path given.
|
126
|
+
#
|
127
|
+
# @step_input request_type [String] The type of request (error, session, build, etc)
|
128
|
+
# @step_input field_path [String] The field to sort by
|
129
|
+
Then('I sort the {word} by the payload field {string}') do |request_type, field_path|
|
130
|
+
list = Maze::Server.list_for(request_type)
|
131
|
+
list.sort_by! field_path
|
132
|
+
end
|
133
|
+
|
134
|
+
# Verify that at least a certain amount of requests have been received
|
135
|
+
# This step is only intended for use in stress tests
|
136
|
+
#
|
137
|
+
# @step_input min_received [Integer] The minimum amount of requests required to pass
|
138
|
+
# @step_input request_type [String] The type of request (error, session, build, etc)
|
139
|
+
Then('I have received at least {int} {word}') do |min_received, request_type|
|
140
|
+
list = Maze::Server.list_for(request_type)
|
141
|
+
Maze.check.operator(list.size_remaining, :>=, min_received, "Actually received #{list.size_remaining} #{request_type} requests")
|
142
|
+
end
|
143
|
+
|
144
|
+
# Assert that the test Server hasn't received any requests - of a specific, or any, type.
|
145
|
+
#
|
146
|
+
# @step_input request_type [String] The type of request ('error', 'session', build, etc), or 'requests' to assert on all
|
147
|
+
# request types.
|
148
|
+
Then('I should receive no {word}') do |request_type|
|
149
|
+
sleep Maze.config.receive_no_requests_wait
|
150
|
+
if request_type == 'requests'
|
151
|
+
# Assert that the test Server hasn't received any requests at all.
|
152
|
+
Maze.check.equal(0, Maze::Server.errors.size_remaining, "#{Maze::Server.errors.size_remaining} errors received")
|
153
|
+
Maze.check.equal(0, Maze::Server.sessions.size_remaining, "#{Maze::Server.sessions.size_remaining} sessions received")
|
154
|
+
else
|
155
|
+
list = Maze::Server.list_for(request_type)
|
156
|
+
Maze.check.equal(0, list.size_remaining, "#{list.size_remaining} #{request_type} received")
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
# Moves to the next request
|
161
|
+
#
|
162
|
+
# @step_input request_type [String] The type of request (error, session, build, etc)
|
163
|
+
Then('I discard the oldest {word}') do |request_type|
|
164
|
+
raise "No #{request_type} to discard" if Maze::Server.list_for(request_type).current.nil?
|
165
|
+
|
166
|
+
Maze::Server.list_for(request_type).next
|
167
|
+
end
|
168
|
+
|
169
|
+
Then('the received errors match:') do |table|
|
170
|
+
# Checks that each request matches one of the event fields
|
171
|
+
requests = Maze::Server.errors.remaining
|
172
|
+
match_count = 0
|
173
|
+
|
174
|
+
# iterate through each row in the table. exactly 1 request should match each row.
|
175
|
+
table.hashes.each do |row|
|
176
|
+
requests.each do |request|
|
177
|
+
# Skip if no body.events in this request
|
178
|
+
next if (!request.key? :body) || (!request[:body].key? 'events')
|
179
|
+
|
180
|
+
events = request[:body]['events']
|
181
|
+
Maze.check.equal(1, events.length, 'Expected exactly one event per request')
|
182
|
+
match_count += 1 if Maze::Assertions::RequestSetAssertions.request_matches_row(events[0], row)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
Maze.check.equal(requests.size, match_count, 'Unexpected number of requests matched the received payloads')
|
186
|
+
end
|
@@ -0,0 +1,428 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
require_relative '../../maze/wait'
|
3
|
+
|
4
|
+
# @!group Runner steps
|
5
|
+
|
6
|
+
# Sets an environment variable for subsequent scripts or commands.
|
7
|
+
#
|
8
|
+
# @step_input key [String] The environment variable
|
9
|
+
# @step_input value [String] The intended value of the environment variable
|
10
|
+
When('I set environment variable {string} to {string}') do |key, value|
|
11
|
+
Maze::Runner.environment[key] = value
|
12
|
+
end
|
13
|
+
|
14
|
+
# Sets an environment variable to a given endpoint.
|
15
|
+
#
|
16
|
+
# @step_input endpoint [String] The endpoint to set
|
17
|
+
# @step_input name [String] The environment variable
|
18
|
+
When('I store the {word} endpoint in the environment variable {string}') do |endpoint, name|
|
19
|
+
steps %(
|
20
|
+
When I set environment variable "#{name}" to "http://maze-runner:#{Maze.config.port}/#{endpoint}"
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Sets an environment variable to the currently set API key.
|
25
|
+
#
|
26
|
+
# @step_input name [String] The environment variable
|
27
|
+
When('I store the api key in the environment variable {string}') do |name|
|
28
|
+
steps %Q{
|
29
|
+
When I set environment variable "#{name}" to "#{$api_key}"
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
# Runs a script, blocking until it returns.
|
34
|
+
#
|
35
|
+
# @step_input script_path [String] Path to the script to be run
|
36
|
+
When('I run the script {string} synchronously') do |script_path|
|
37
|
+
Maze::Runner.run_script(script_path, blocking: true)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Runs a script with a given interpreter, blocking until it returns.
|
41
|
+
#
|
42
|
+
# @step_input script_path [String] Path to the script to be run
|
43
|
+
# @step_input command [String] The command to run the script with, e.g. 'ruby'
|
44
|
+
When('I run the script {string} using {word} synchronously') do |script_path, command|
|
45
|
+
Maze::Runner.run_script(script_path, blocking: true, command: command)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Runs a script.
|
49
|
+
#
|
50
|
+
# @step_input script_path [String] Path to the script to be run
|
51
|
+
When('I run the script {string}') do |script_path|
|
52
|
+
Maze::Runner.run_script script_path
|
53
|
+
end
|
54
|
+
|
55
|
+
# Starts a docker-compose service.
|
56
|
+
#
|
57
|
+
# @step_input service [String] The name of the service to run
|
58
|
+
When('I start the service {string}') do |service|
|
59
|
+
Maze::Docker.start_service service
|
60
|
+
end
|
61
|
+
|
62
|
+
# Runs a docker-compose service using a specific command.
|
63
|
+
#
|
64
|
+
# @step_input service [String] The name of the service to run
|
65
|
+
# @step_input command [String] The command to run inside the service
|
66
|
+
When('I run the service {string} with the command {string}') do |service, command|
|
67
|
+
Maze::Docker.start_service(service, command: command)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Runs a docker-compose service in an interactive CLI.
|
71
|
+
#
|
72
|
+
# @step_input service [String] The name of the service to run
|
73
|
+
When('I run the service {string} interactively') do |service|
|
74
|
+
# Stop the old session if one exists
|
75
|
+
step('I stop the current shell') if Maze::Runner.interactive_session?
|
76
|
+
|
77
|
+
Maze::Docker.start_service(service, interactive: true)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Runs a docker-compose service using a specific command in an interactive CLI.
|
81
|
+
#
|
82
|
+
# @step_input service [String] The name of the service to run
|
83
|
+
# @step_input command [String] The command to run inside the service
|
84
|
+
When('I run the service {string} with the command {string} interactively') do |service, command|
|
85
|
+
# Stop the old session if one exists
|
86
|
+
step('I stop the current shell') if Maze::Runner.interactive_session?
|
87
|
+
|
88
|
+
Maze::Docker.start_service(service, command: command, interactive: true)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Runs a docker-compose service using a specific command provided as a Gherkin multi-line string.
|
92
|
+
#
|
93
|
+
# @step_input service [String] The name of the service to run
|
94
|
+
# @step_input command [String] The command to run inside the service (as a Gherkin multi-line string)
|
95
|
+
When('I run the service {string} with the command') do |service, command|
|
96
|
+
one_line_cmd = command.gsub("\n", ' ').gsub(/ +/, ' ')
|
97
|
+
Maze::Docker.start_service(service, command: one_line_cmd)
|
98
|
+
end
|
99
|
+
|
100
|
+
# Executes a command in the given docker compose service.
|
101
|
+
#
|
102
|
+
# The service must already be running for this to succeed as it uses 'docker
|
103
|
+
# compose exec'.
|
104
|
+
#
|
105
|
+
# @step_input command [String] The command to run inside the service
|
106
|
+
# @step_input service [String] The name of the service
|
107
|
+
When('I execute the command {string} in the service {string}') do |command, service|
|
108
|
+
Maze::Docker.exec(service, command)
|
109
|
+
end
|
110
|
+
|
111
|
+
# Executes a command in the given docker compose service in the background.
|
112
|
+
#
|
113
|
+
# The service must already be running for this to succeed as it uses 'docker
|
114
|
+
# compose exec --detach'.
|
115
|
+
#
|
116
|
+
# @step_input command [String] The command to run inside the service
|
117
|
+
# @step_input service [String] The name of the service
|
118
|
+
When('I execute the command {string} in the service {string} in the background') do |command, service|
|
119
|
+
Maze::Docker.exec(service, command, detach: true)
|
120
|
+
end
|
121
|
+
|
122
|
+
# Allows validation of the last exit code of the last run docker-compose command.
|
123
|
+
# Will fail if no commands have been run.
|
124
|
+
#
|
125
|
+
# @step_input expected_code [Integer] The expected exit code
|
126
|
+
Then('the exit code of the last docker command was {int}') do |expected_code|
|
127
|
+
wait = Maze::Wait.new(timeout: Maze.config.receive_requests_wait)
|
128
|
+
success = wait.until { !Maze::Docker.last_exit_code.nil? }
|
129
|
+
|
130
|
+
Maze.check.true(success, 'No docker exit code available to verify')
|
131
|
+
Maze.check.equal(Maze::Docker.last_exit_code, expected_code)
|
132
|
+
end
|
133
|
+
|
134
|
+
# A shortcut for the above assuming 0 as a successful exit code
|
135
|
+
# Will fail if no commands have been run
|
136
|
+
Then('the last run docker command exited successfully') do
|
137
|
+
step('the exit code of the last docker command was 0')
|
138
|
+
end
|
139
|
+
|
140
|
+
# Allows testing that the last exit code was not 0
|
141
|
+
# Will fail if no commands have been run
|
142
|
+
Then('the last run docker command did not exit successfully') do
|
143
|
+
wait = Maze::Wait.new(timeout: Maze.config.receive_requests_wait)
|
144
|
+
success = wait.until { !Maze::Docker.last_exit_code.nil? }
|
145
|
+
|
146
|
+
Maze.check.true(success, 'No docker exit code available to verify')
|
147
|
+
Maze.check.not_equal(Maze::Docker.last_exit_code, 0)
|
148
|
+
end
|
149
|
+
|
150
|
+
# Allows testing a docker command output a specific string
|
151
|
+
# Will fail if no commands have been run
|
152
|
+
#
|
153
|
+
# @step_input expected_string [String] The string expected in a single log line
|
154
|
+
Then('the last run docker command output {string}') do |expected_string|
|
155
|
+
wait = Maze::Wait.new(timeout: Maze.config.receive_requests_wait)
|
156
|
+
success = wait.until { !Maze::Docker.last_command_logs.nil? }
|
157
|
+
|
158
|
+
Maze.check.true(success, 'No docker logs available to verify')
|
159
|
+
|
160
|
+
docker_output = Maze::Docker.last_command_logs
|
161
|
+
output_included = docker_output.any? { |line| line.include?(expected_string) }
|
162
|
+
|
163
|
+
Maze.check.true(output_included, %(
|
164
|
+
No line of output included '#{expected_string}'.
|
165
|
+
Full output:
|
166
|
+
#{docker_output.join('\n')}
|
167
|
+
))
|
168
|
+
end
|
169
|
+
|
170
|
+
# Waits for a number of seconds, performing no actions.
|
171
|
+
#
|
172
|
+
# @step_input seconds [Integer] The number of seconds to sleep for
|
173
|
+
When('I wait for {int} second(s)') do |seconds|
|
174
|
+
$logger.warn 'Sleep was used! Please avoid using sleep in tests!'
|
175
|
+
sleep(seconds)
|
176
|
+
end
|
177
|
+
|
178
|
+
# Starts an interactive shell
|
179
|
+
When('I start a new shell') do
|
180
|
+
# Stop the old session if one exists
|
181
|
+
step('I stop the current shell') if Maze::Runner.interactive_session?
|
182
|
+
|
183
|
+
Maze::Runner.start_interactive_session
|
184
|
+
end
|
185
|
+
|
186
|
+
# Stops currently running interactive shell
|
187
|
+
When('I stop the current shell') do
|
188
|
+
shell = Maze::Runner.interactive_session
|
189
|
+
result = Maze::Runner.stop_interactive_session
|
190
|
+
|
191
|
+
Maze.check.true(result, 'The shell is still running when it should have exited')
|
192
|
+
Maze.check.false(shell.running?, 'The shell is still running when it should have exited')
|
193
|
+
end
|
194
|
+
|
195
|
+
# Run a command on the shell
|
196
|
+
#
|
197
|
+
# @step_input command [String] The command to run on the shell
|
198
|
+
When('I input {string} interactively') do |command|
|
199
|
+
current_shell = Maze::Runner.interactive_session
|
200
|
+
success = current_shell.run_command(command)
|
201
|
+
Maze.check.true(success, 'The terminal had already closed')
|
202
|
+
end
|
203
|
+
|
204
|
+
# Send a return or enter to the interactive session
|
205
|
+
When('I input a return interactively') do
|
206
|
+
step('I input "" interactively')
|
207
|
+
end
|
208
|
+
|
209
|
+
# Assert the current stdout line in the shell exactly matches the given string
|
210
|
+
#
|
211
|
+
# @step_input expected [String] The expected string
|
212
|
+
Then('the current stdout line is {string}') do |expected|
|
213
|
+
current_shell = Maze::Runner.interactive_session
|
214
|
+
Maze.check.equal(expected, current_shell.current_buffer)
|
215
|
+
end
|
216
|
+
|
217
|
+
# Assert the current stdout line in the shell includes the given string
|
218
|
+
#
|
219
|
+
# @step_input expected [String] The expected string
|
220
|
+
Then('the current stdout line contains {string}') do |expected|
|
221
|
+
current_shell = Maze::Runner.interactive_session
|
222
|
+
Maze.check.include(current_shell.current_buffer, expected)
|
223
|
+
end
|
224
|
+
|
225
|
+
# Waits for a line matching a regex to be present in the current stdout
|
226
|
+
# Times out after Maze.config.receive_requests_wait seconds.
|
227
|
+
#
|
228
|
+
# @step_input regex [String] The regex to match against
|
229
|
+
Then('I wait for the current stdout line to match the regex {string}') do |regex|
|
230
|
+
wait = Maze::Wait.new(timeout: Maze.config.receive_requests_wait)
|
231
|
+
shell = Maze::Runner.interactive_session
|
232
|
+
|
233
|
+
success = wait.until { shell.current_buffer.match?(regex) }
|
234
|
+
|
235
|
+
Maze.check.true(success, "The current output line \"#{shell.current_buffer}\" did not match \"#{regex}\"")
|
236
|
+
end
|
237
|
+
|
238
|
+
# Waits for a specific shell prompt to be present in the buffered stdout line,
|
239
|
+
# timing out after Maze.config.receive_requests_wait seconds.
|
240
|
+
#
|
241
|
+
# @step_input expected_prompt [String] The prompt expected in the current buffer
|
242
|
+
Then('I wait for the shell prompt {string}') do |expected_prompt|
|
243
|
+
wait = Maze::Wait.new(timeout: Maze.config.receive_requests_wait)
|
244
|
+
shell = Maze::Runner.interactive_session
|
245
|
+
|
246
|
+
success = wait.until { shell.current_buffer == expected_prompt }
|
247
|
+
|
248
|
+
Maze.check.true(success, "The current output line \"#{shell.current_buffer}\" did not match \"#{expected_prompt}\"")
|
249
|
+
end
|
250
|
+
|
251
|
+
# Verify a string appears in the stdout logs
|
252
|
+
#
|
253
|
+
# @step_input expected_line [String] The string present in stdout logs
|
254
|
+
Then('the shell has output {string} to stdout') do |expected_line|
|
255
|
+
current_shell = Maze::Runner.interactive_session
|
256
|
+
match = current_shell.stdout_lines.any? { |line| line == expected_line }
|
257
|
+
Maze.check.true(match, "No output lines from #{current_shell.stdout_lines} matched #{expected_line}")
|
258
|
+
end
|
259
|
+
|
260
|
+
# Wait for a string to appear in the stdout logs, timing out after Maze.config.receive_requests_wait seconds.
|
261
|
+
#
|
262
|
+
# @step_input expected_line [String] The string present in stdout logs
|
263
|
+
Then('I wait for the shell to output {string} to stdout') do |expected_line|
|
264
|
+
wait = Maze::Wait.new(timeout: Maze.config.receive_requests_wait)
|
265
|
+
current_shell = Maze::Runner.interactive_session
|
266
|
+
|
267
|
+
success = wait.until do
|
268
|
+
current_shell.stdout_lines.any? { |line| line == expected_line }
|
269
|
+
end
|
270
|
+
|
271
|
+
Maze.check.true(success, "No output lines from #{current_shell.stdout_lines} matched #{expected_line}")
|
272
|
+
end
|
273
|
+
|
274
|
+
# Verify a string using a regex in the stdout logs
|
275
|
+
#
|
276
|
+
# @step_input regex_matcher [String] The regex expected to match a line in stdout logs
|
277
|
+
Then('the shell has output a match for the regex {string} to stdout') do |regex_matcher|
|
278
|
+
current_shell = Maze::Runner.interactive_session
|
279
|
+
match = current_shell.stdout_lines.any? { |line| line.match?(regex_matcher) }
|
280
|
+
Maze.check.true(match, "No output lines from #{current_shell.stdout_lines} matched #{regex_matcher}")
|
281
|
+
end
|
282
|
+
|
283
|
+
# Wait for a string matching a regex in the stdout logs, timing out after Maze.config.receive_requests_wait seconds.
|
284
|
+
#
|
285
|
+
# @step_input regex_matcher [String] The regex expected to match a line in stdout logs
|
286
|
+
Then('I wait for the shell to output a match for the regex {string} to stdout') do |regex_matcher|
|
287
|
+
wait = Maze::Wait.new(timeout: Maze.config.receive_requests_wait)
|
288
|
+
current_shell = Maze::Runner.interactive_session
|
289
|
+
|
290
|
+
success = wait.until do
|
291
|
+
current_shell.stdout_lines.any? { |line| line.match?(regex_matcher) }
|
292
|
+
end
|
293
|
+
|
294
|
+
Maze.check.true(success, "No output lines from #{current_shell.stdout_lines} matched #{regex_matcher}")
|
295
|
+
end
|
296
|
+
|
297
|
+
# Wait for the shell to output a number of strings in STDOUT, as defined by a table.
|
298
|
+
# This step will time out after Maze.config.receive_requests_wait seconds.
|
299
|
+
#
|
300
|
+
# @step_input expected_lines [Array] An array of strings expected in STDOUT
|
301
|
+
Then('I wait for the interactive shell to output the following lines in stdout') do |expected_lines|
|
302
|
+
wait = Maze::Wait.new(timeout: Maze.config.receive_requests_wait)
|
303
|
+
current_shell = Maze::Runner.interactive_session
|
304
|
+
|
305
|
+
success = wait.until do
|
306
|
+
current_stdout = current_shell.stdout_lines.join("\n")
|
307
|
+
current_stdout.include?(expected_lines)
|
308
|
+
end
|
309
|
+
|
310
|
+
Maze.check.true(
|
311
|
+
success,
|
312
|
+
"Lines present in stdout: #{current_shell.stdout_lines} did not include all of: #{expected_lines}"
|
313
|
+
)
|
314
|
+
end
|
315
|
+
|
316
|
+
# Verify a string appears in the stderr logs
|
317
|
+
#
|
318
|
+
# @step_input expected_err [String] The string present in stderr logs
|
319
|
+
Then('the shell has output {string} to stderr') do |expected_err|
|
320
|
+
current_shell = Maze::Runner.interactive_session
|
321
|
+
match = current_shell.stderr_lines.any? { |line| line == expected_err }
|
322
|
+
Maze.check.true(match, "No output lines from #{current_shell.stderr_lines} matched #{expected_err}")
|
323
|
+
end
|
324
|
+
|
325
|
+
# Wait for a string to appear in the stderr logs
|
326
|
+
#
|
327
|
+
# @step_input expected_line [String] The string present in stderr logs
|
328
|
+
Then('I wait for the shell to output {string} to stderr') do |expected_line|
|
329
|
+
wait = Maze::Wait.new(timeout: Maze.config.receive_requests_wait)
|
330
|
+
current_shell = Maze::Runner.interactive_session
|
331
|
+
|
332
|
+
success = wait.until do
|
333
|
+
current_shell.stderr_lines.any? { |line| line == expected_line }
|
334
|
+
end
|
335
|
+
|
336
|
+
Maze.check.true(success, "No output lines from #{current_shell.stderr_lines} matched #{expected_line}")
|
337
|
+
end
|
338
|
+
|
339
|
+
# Verify the last interactive command exited successfully (assuming a 0 is a success)
|
340
|
+
Then('the last interactive command exited successfully') do
|
341
|
+
Maze.check.true(
|
342
|
+
Maze::Runner.interactive_session?,
|
343
|
+
'No interactive session is running so the exit code cannot be checked'
|
344
|
+
)
|
345
|
+
|
346
|
+
uuid = SecureRandom.uuid
|
347
|
+
|
348
|
+
steps %Q{
|
349
|
+
When I input "[ $? = 0 ] && echo '#{uuid} exited with 0' || echo '#{uuid} exited with error'" interactively
|
350
|
+
Then I wait for the shell to output a match for the regex "#{uuid} exited with 0" to stdout
|
351
|
+
}
|
352
|
+
end
|
353
|
+
|
354
|
+
# Verify the exit code of the last interactive command
|
355
|
+
#
|
356
|
+
# @step_input exit_code [Integer] The expected exit code
|
357
|
+
Then('the last interactive command exit code is {int}') do |exit_code|
|
358
|
+
Maze.check.true(
|
359
|
+
Maze::Runner.interactive_session?,
|
360
|
+
'No interactive session is running so the exit code cannot be checked'
|
361
|
+
)
|
362
|
+
|
363
|
+
uuid = SecureRandom.uuid
|
364
|
+
|
365
|
+
steps %Q{
|
366
|
+
When I input "echo #{uuid} $?" interactively
|
367
|
+
Then I wait for the shell to output a match for the regex "#{uuid} #{exit_code}" to stdout
|
368
|
+
}
|
369
|
+
end
|
370
|
+
|
371
|
+
# Assert that the last interactive command exited with an error code (assuming non-0 is an error)
|
372
|
+
Then('the last interactive command exited with an error code') do
|
373
|
+
Maze.check.true(
|
374
|
+
Maze::Runner.interactive_session?,
|
375
|
+
'No interactive session is running so the exit code cannot be checked'
|
376
|
+
)
|
377
|
+
|
378
|
+
uuid = SecureRandom.uuid
|
379
|
+
|
380
|
+
steps %Q{
|
381
|
+
When I input "[ $? = 0 ] && echo '#{uuid} exited with 0' || echo '#{uuid} exited with error'" interactively
|
382
|
+
Then I wait for the shell to output a match for the regex "#{uuid} exited with error" to stdout
|
383
|
+
}
|
384
|
+
end
|
385
|
+
|
386
|
+
# Assert that an expected_line is present in a file located relative to the interactive terminal's CWD
|
387
|
+
#
|
388
|
+
# @step_input filename [String] The file tested, relative to the CWD of the interactive terminal
|
389
|
+
# @step_input expected_line [String] The line expected in the file
|
390
|
+
Then('the interactive file {string} contains {string}') do |filename, expected_line|
|
391
|
+
steps %(
|
392
|
+
When I input "fgrep '#{expected_line.gsub(/"/, '\"')}' #{filename}" interactively
|
393
|
+
And I wait for the current stdout line to match the regex "[#>$]\\s?"
|
394
|
+
Then the last interactive command exited successfully
|
395
|
+
)
|
396
|
+
end
|
397
|
+
|
398
|
+
# Assert that a line is not present in a file located relative to the interactive terminal's CWD
|
399
|
+
#
|
400
|
+
# @step_input filename [String] The file tested, relative to the CWD of the interactive terminal
|
401
|
+
# @step_input excluded_line [String] The line that should not be present be in the file
|
402
|
+
Then('the interactive file {string} does not contain {string}') do |filename, excluded_line|
|
403
|
+
steps %(
|
404
|
+
When I input "fgrep '#{excluded_line.gsub(/"/, '\"')}' #{filename}" interactively
|
405
|
+
And I wait for the current stdout line to match the regex "[#>$]\\s?"
|
406
|
+
Then the last interactive command exited with an error code
|
407
|
+
)
|
408
|
+
end
|
409
|
+
|
410
|
+
# Assert that a file located relative to the CWD of the interactive terminal contains all of the expected lines
|
411
|
+
#
|
412
|
+
# @step_input filename [String] The file tested, relative to the CWD of the interactive terminal
|
413
|
+
# @step_input expected_lines [String] The lines expected in the file as a multi-line string
|
414
|
+
Then('the interactive file {string} contains:') do |filename, expected_lines|
|
415
|
+
expected_lines.each_line do |line|
|
416
|
+
step("the interactive file '#{filename}' contains '#{line.chomp}'")
|
417
|
+
end
|
418
|
+
end
|
419
|
+
|
420
|
+
# Assert that a file located relative to the CWD of the interactive terminal does not contain any of the excluded lines
|
421
|
+
#
|
422
|
+
# @step_input filename [String] The file tested, relative to the CWD of the interactive terminal
|
423
|
+
# @step_input excluded_lines [String] The lines that should not be present in the file, as a multi-line string
|
424
|
+
Then('the interactive file {string} does not contain:') do |filename, excluded_lines|
|
425
|
+
excluded_lines.each_line do |line|
|
426
|
+
step("the interactive file '#{filename}' does not contain '#{line.chomp}'")
|
427
|
+
end
|
428
|
+
end
|