Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maze runner tidy up #429

Merged
merged 3 commits into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 12 additions & 28 deletions features/steps/laravel_steps.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'net/http'

Given(/^I enable session tracking$/) do
steps %{
When I set environment variable "BUGSNAG_CAPTURE_SESSIONS" to "true"
Expand All @@ -15,32 +13,27 @@

When(/^I start the laravel fixture$/) do
steps %{
When I start the service "#{fixture}"
And I wait for the host "localhost" to open port "#{fixture_port}"
When I start the service "#{Laravel.fixture}"
And I wait for the host "localhost" to open port "#{Laravel.fixture_port}"
}
end

When("I navigate to the route {string}") do |route|
navigate_to(route)
Laravel.navigate_to(route)
end

Then("the exception {string} matches one of the following:") do |path, values|
desired_value = read_key_path(Server.current_request[:body], "events.0.exceptions.0.#{path}")
assert_includes(values.raw.flatten, desired_value)
end
Then("the Laravel response matches {string}") do |regex|
wait = Maze::Wait.new(timeout: 10)
success = wait.until { Laravel.last_response != nil }

raise 'No response from the Laravel fixture!' unless success

def fixture
ENV['LARAVEL_FIXTURE'] || 'laravel56'
assert_match(Regexp.new(regex), Laravel.last_response)
end

def fixture_port
case fixture
when 'laravel-latest' then 61299
when 'laravel66' then 61266
when 'laravel58' then 61258
when 'laravel56' then 61256
else raise "Unknown laravel fixture '#{ENV['LARAVEL_FIXTURE']}'!"
end
Then("the exception {string} matches one of the following:") do |path, values|
desired_value = read_key_path(Server.current_request[:body], "events.0.exceptions.0.#{path}")
assert_includes(values.raw.flatten, desired_value)
end

def current_ip
Expand All @@ -50,12 +43,3 @@ def current_ip
ip_list = /((?:[0-9]*\.){3}[0-9]*)/.match(ip_addr)
ip_list.captures.first
end

def navigate_to(route, attempts = 0)
Net::HTTP.get('localhost', route, fixture_port)
rescue => e
raise "Failed to navigate to #{route} (#{e})" if attempts > 15

sleep 1
navigate_to(route, attempts + 1)
end
29 changes: 21 additions & 8 deletions features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,39 @@

# Copy bugsnag-laravel into fixture directories
FIXTURE_DIR = 'features/fixtures'
VENDORED_LIB = FIXTURE_DIR + '/bugsnag-laravel.zip'
VENDORED_LIB = "#{FIXTURE_DIR}/bugsnag-laravel.zip"
FILES_TO_CLEANUP = [VENDORED_LIB]

`composer archive -f zip --dir=#{File.dirname(VENDORED_LIB)} --file=#{File.basename(VENDORED_LIB, '.zip')}`
Dir.glob(FIXTURE_DIR + '/laravel*').each do |directory|

Dir.glob("#{FIXTURE_DIR}/laravel*").each do |directory|
next if directory.end_with?('laravel-latest')

FileUtils.cp(VENDORED_LIB, directory + '/bugsnag-laravel.zip')
zip = "#{directory}/bugsnag-laravel.zip"
FILES_TO_CLEANUP << zip

FileUtils.cp(VENDORED_LIB, zip)

# Remove any locally installed composer deps
FileUtils.rm_rf(directory + '/vendor')
FileUtils.rm_rf("#{directory}/vendor")
end


# Copy current requirements into fixture requirements
File.open('composer.json', 'r') do |source|
parsed_composer = JSON.parse(source.read)
requirements = parsed_composer["require"]

Dir.glob(FIXTURE_DIR + '/laravel*').each do |directory|
Dir.glob("#{FIXTURE_DIR}/laravel*").each do |directory|
next if directory.end_with?('laravel-latest')

File.open(directory + '/composer.json.template', 'r') do |template|
parsed_template = JSON.parse template.read
parsed_template["repositories"][0]["package"]["require"] = requirements

File.open(directory + '/composer.json', 'w') do |target|
composer_json = "#{directory}/composer.json"
FILES_TO_CLEANUP << composer_json

File.open(composer_json, 'w') do |target|
target.write(JSON.pretty_generate(parsed_template))
end
end
Expand All @@ -37,10 +45,15 @@
Before do
ENV["BUGSNAG_API_KEY"] = $api_key
ENV["BUGSNAG_ENDPOINT"] = "http://#{current_ip}:9339"
Laravel.reset!
end

at_exit do
FileUtils.rm_rf(VENDORED_LIB)
project_root = File.dirname(File.dirname(__dir__))

FILES_TO_CLEANUP.each do |file|
FileUtils.rm_rf("#{project_root}/#{file}")
end
end

AfterConfiguration do |_config|
Expand Down
34 changes: 34 additions & 0 deletions features/support/laravel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require 'net/http'

class Laravel
class << self
attr_reader :last_response

def reset!
@last_response = nil
end

def navigate_to(route, attempts = 0)
@last_response = Net::HTTP.get('localhost', route, fixture_port)
rescue => e
raise "Failed to navigate to #{route} (#{e})" if attempts > 15

sleep 1
navigate_to(route, attempts + 1)
end

def fixture
ENV.fetch('LARAVEL_FIXTURE', 'laravel56')
end

def fixture_port
case fixture
when 'laravel-latest' then 61299
when 'laravel66' then 61266
when 'laravel58' then 61258
when 'laravel56' then 61256
else raise "Unknown laravel fixture '#{ENV['LARAVEL_FIXTURE']}'!"
end
end
end
end