diff options
author | Azul <azul@riseup.net> | 2016-06-09 13:51:02 +0200 |
---|---|---|
committer | Azul <azul@riseup.net> | 2016-06-09 13:51:02 +0200 |
commit | b4075771b2b1f3c688496d18d7a5a5f1db952004 (patch) | |
tree | a35d157bb5727c207ea8c21ca0990f3230bca3ca /test | |
parent | 56263b6512f60cf055a925f5446f1f504bb65a4d (diff) |
refactor: remove EM specific stuff from Hkp::FetchKey interface
Diffstat (limited to 'test')
-rw-r--r-- | test/integration/hkp_test.rb | 33 | ||||
-rw-r--r-- | test/unit/adapters/em_http_test.rb | 25 |
2 files changed, 44 insertions, 14 deletions
diff --git a/test/integration/hkp_test.rb b/test/integration/hkp_test.rb index 0e77253..6ef52fe 100644 --- a/test/integration/hkp_test.rb +++ b/test/integration/hkp_test.rb @@ -29,17 +29,13 @@ class HkpTest < Minitest::Test def test_key_info_not_found uid = 'leaping_lemur@leap.se' stub_sks_vindex_reponse(uid, status: 404) - test_em_errback "Nickserver::Hkp::FetchKeyInfo.new.search '#{uid}'" do |error| - assert_equal 404, error - end + assert_response_status_for_uid uid, 404 end def test_no_matching_key_found uid = 'leaping_lemur@leap.se' stub_sks_vindex_reponse(uid, status: 200) - test_em_errback "Nickserver::Hkp::FetchKeyInfo.new.search '#{uid}'" do |error| - assert_equal 404, error - end + assert_response_status_for_uid uid, 404 end def test_fetch_key @@ -48,8 +44,8 @@ class HkpTest < Minitest::Test stub_sks_vindex_reponse(uid, body: file_content(:leap_vindex_result)) stub_sks_get_reponse(key_id, body: file_content(:leap_public_key)) - test_em_callback "Nickserver::Hkp::FetchKey.new.get '#{uid}'" do |key_text| - assert_equal file_content(:leap_public_key), key_text + assert_response_for_uid(uid) do |response| + assert_equal file_content(:leap_public_key), response.body end end @@ -60,18 +56,14 @@ class HkpTest < Minitest::Test stub_sks_vindex_reponse(uid, body: file_content(:leap_vindex_result)) stub_sks_get_reponse(key_id, status: 404) - test_em_errback "Nickserver::Hkp::FetchKey.new.get '#{uid}'" do |error| - assert_equal 404, error - end + assert_response_status_for_uid uid, 404 end def test_fetch_key_too_short uid = 'chiiph@leap.se' stub_sks_vindex_reponse(uid, body: file_content(:short_key_vindex_result)) - test_em_errback "Nickserver::Hkp::FetchKey.new.get '#{uid}'" do |error| - assert_equal 500, error - end + assert_response_status_for_uid uid, 500 end # @@ -110,6 +102,19 @@ class HkpTest < Minitest::Test protected + def assert_response_status_for_uid(uid, status) + assert_response_for_uid(uid) do |response| + assert_equal status, response.status + end + end + + def assert_response_for_uid(uid, &block) + EM.run do + Nickserver::Hkp::FetchKey.new(nil).get(uid, &block) + EM.stop + end + end + # # Takes a code snippet that returns a Deferrable, and yields the callback result. # Assertion fails if errback is called instead of callback. diff --git a/test/unit/adapters/em_http_test.rb b/test/unit/adapters/em_http_test.rb new file mode 100644 index 0000000..659ff1b --- /dev/null +++ b/test/unit/adapters/em_http_test.rb @@ -0,0 +1,25 @@ +require 'test_helper' +require 'nickserver/adapters/em_http' + +class Nickserver::Adapters::EmHttpTest < Minitest::Test + + def test_successful_request + url = 'http://url.to' + stub_http_request(:get, url) + .with(query: {key: :value}) + .to_return status: 200, body: 'body' + EM.run do + adapter.get(url, query: {key: :value}) do |status, body| + assert_equal 200, status + assert_equal 'body', body + EM.stop + end + end + end + + protected + + def adapter + Nickserver::Adapters::EmHttp.new + end +end |