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

e2e tests: additional checks for application/json response headers #2609

Merged
merged 4 commits into from
Apr 15, 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
20 changes: 10 additions & 10 deletions test/e2e/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,25 @@ end
task :fixture_wallets_template do
puts "\n >> Creating #{FIXTURES_FILE}"

fixture_wallets = { :linux => {:shelley => mnemonic_sentence(24),
fixture_wallets = { :linux => { :shelley => mnemonic_sentence(24),
:icarus => mnemonic_sentence(15),
:byron => mnemonic_sentence(12) },
:macos => {:shelley => mnemonic_sentence(24),
:macos => { :shelley => mnemonic_sentence(24),
:icarus => mnemonic_sentence(15),
:byron => mnemonic_sentence(12) },
:windows => {:shelley => mnemonic_sentence(24),
:windows => { :shelley => mnemonic_sentence(24),
:icarus => mnemonic_sentence(15),
:byron => mnemonic_sentence(12) }
}
if File.exists?(FIXTURES_FILE)
err = %Q{
err = "
File #{FIXTURES_FILE} already exists!
I don't want to overwrite it in case it
contains fixture wallets already...
}
"
STDERR.puts err
else
File.open(FIXTURES_FILE, 'w') {|f| f.write JSON.pretty_generate(fixture_wallets) }
File.open(FIXTURES_FILE, 'w') { |f| f.write JSON.pretty_generate(fixture_wallets) }
end

end
Expand Down Expand Up @@ -209,7 +209,7 @@ task :get_latest_configs, [:env] do |task, args|
env = args[:env]
out = File.join(CONFIGS, env)

if (File.exist?(out) and not File.writable?(out))
if (File.exist?(out) && (not File.writable?(out)))
# The config directory is probably a /nix/store path
puts "\n >> Using config directory '#{out}'"
else
Expand All @@ -227,16 +227,16 @@ task :get_latest_configs, [:env] do |task, args|
# remove environment names from genesis files
config = File.read(config_file)
config_edited = config.gsub(/#{env}-([^-]+)-genesis.json/, 'genesis-\1.json')
File.open(config_file, "w") {|file| file.puts config_edited }
File.open(config_file, "w") { |file| file.puts config_edited }
end
end

task :get_docker_logs do
puts "\n >> Getting docker logs into #{LOGS}"

mk_dir(LOGS)
node_logfile = `docker inspect --format='{{.LogPath}}' cardano-node`.gsub("\n",'')
wallet_logfile = `docker inspect --format='{{.LogPath}}' cardano-wallet`.gsub("\n",'')
node_logfile = `docker inspect --format='{{.LogPath}}' cardano-node`.gsub("\n", '')
wallet_logfile = `docker inspect --format='{{.LogPath}}' cardano-wallet`.gsub("\n", '')

cmd "sudo cp #{node_logfile} #{LOGS}/node.log"
cmd "sudo cp #{wallet_logfile} #{LOGS}/wallet.log"
Expand Down
86 changes: 62 additions & 24 deletions test/e2e/helpers/matchers.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,67 @@
require "rspec/expectations"

RSpec::Matchers.define :have_http do |code|
match do |response|
RSpec::Matchers.define :be_correct_and_respond do |code|
match do |response|
if code == 204
response.code == code
else
((response.code == code) && ({ 'content-type' => ['application/json;charset=utf-8'] } <= response.headers))
end
failure_message do |response|
method = response.request.http_method.to_s.split('::').last.upcase
uri = response.request.last_uri
body = response.request.options[:body]
headers = response.request.options[:headers]

%Q{
The response did not return expected HTTP code!
Expected code = #{code}
Actual code = #{response.code}

Actual request:
#{method} #{uri}
#{'Body: ' + body if body}
#{'Headers: ' + headers.to_s if headers}

Actual response:
#{response}

Time: #{Time.now}
}
end
end
failure_message do |response|
method = response.request.http_method.to_s.split('::').last.upcase
uri = response.request.last_uri
body = response.request.options[:body]
headers = response.request.options[:headers]

"
The response did not return expected HTTP code or header 'content-type: application/json'!
Expected code = #{code}
Actual code = #{response.code}

Actual request:
#{method} #{uri}
#{'Body: ' + body if body}
#{'Headers: ' + headers.to_s if headers}

Actual response:
#{response}

Actual response headers:
#{response.headers}

Time: #{Time.now}
"
end
end

RSpec::Matchers.define :respond_with do |code|
match do |response|
response.code == code
end
failure_message do |response|
method = response.request.http_method.to_s.split('::').last.upcase
uri = response.request.last_uri
body = response.request.options[:body]
headers = response.request.options[:headers]

"
The response did not return expected HTTP code!
Expected code = #{code}
Actual code = #{response.code}

Actual request:
#{method} #{uri}
#{'Body: ' + body if body}
#{'Headers: ' + headers.to_s if headers}

Actual response:
#{response}

Actual response headers:
#{response.headers}

Time: #{Time.now}
"
end
end
1 change: 0 additions & 1 deletion test/e2e/helpers/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

module Helpers
module Utils

def cmd(cmd)
puts cmd
puts `#{cmd}`
Expand Down
Loading