summaryrefslogtreecommitdiff
path: root/test/unit
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/adapters/celluloid_http_test.rb12
-rw-r--r--test/unit/couch_db/source_unit_test.rb5
-rw-r--r--test/unit/hkp/client_test.rb53
3 files changed, 60 insertions, 10 deletions
diff --git a/test/unit/adapters/celluloid_http_test.rb b/test/unit/adapters/celluloid_http_test.rb
index 87e7f55..4381b8f 100644
--- a/test/unit/adapters/celluloid_http_test.rb
+++ b/test/unit/adapters/celluloid_http_test.rb
@@ -18,18 +18,16 @@ class Nickserver::Adapters::CelluloidHttpTest < Minitest::Test
stub_http_request(:get, url)
.with(query: {key: :value})
.to_return status: 200, body: 'body'
- adapter.get(url, query: {key: :value}) do |status, body|
- assert_equal 200, status
- assert_equal 'body', body
- end
+ status, body = adapter.get(url, query: {key: :value})
+ assert_equal 200, status
+ assert_equal 'body', body
end
def test_https_for_hkp
url = Nickserver::Config.hkp_url
real_network do
- adapter.get url do |status, _body|
- assert_equal 404, status
- end
+ status, _body = adapter.get url
+ assert_equal 404, status
end
end
diff --git a/test/unit/couch_db/source_unit_test.rb b/test/unit/couch_db/source_unit_test.rb
index 19ea9bc..fd07808 100644
--- a/test/unit/couch_db/source_unit_test.rb
+++ b/test/unit/couch_db/source_unit_test.rb
@@ -7,10 +7,9 @@ module Nickserver::CouchDB
def test_query
address = "nick@domain.tl"
adapter = Minitest::Mock.new
- adapter.expect :get, nil,
+ adapter.expect :get, [200, nil],
[String, {query: { reduce: "false", key: "\"#{address}\"" }}]
- query = Source.new(adapter)
- query.query address
+ Source.new(adapter).query address
adapter.verify
end
end
diff --git a/test/unit/hkp/client_test.rb b/test/unit/hkp/client_test.rb
new file mode 100644
index 0000000..9784d0a
--- /dev/null
+++ b/test/unit/hkp/client_test.rb
@@ -0,0 +1,53 @@
+require 'test_helper'
+require 'nickserver/hkp/client'
+
+module Nickserver::Hkp
+ class ClientTest < Minitest::Test
+
+ def test_get_key_infos_by_email
+ adapter_expects_query op: "vindex",
+ search: email,
+ options: "mr",
+ fingerprint: "on",
+ exact: "on"
+ client.get_key_infos_by_email(email)
+ @adapter.verify
+ end
+
+ def test_key_by_fingerprint
+ adapter_expects_query op: "get",
+ search: "0x#{fingerprint}",
+ options: "mr",
+ exact: "on"
+ client.get_key_by_fingerprint(fingerprint)
+ @adapter.verify
+ end
+
+ def client
+ @client ||= Client.new @adapter
+ end
+
+ def adapter_expects_query(query = {})
+ adapter_expects Nickserver::Config.hkp_url, query: query
+ end
+
+ def adapter_expects(*args)
+ @adapter = Minitest::Mock.new
+ @adapter.expect :get, dummy_response,
+ args
+ end
+
+ def email
+ 'dummy_email'
+ end
+
+ def fingerprint
+ 'dummy_fingerprint'
+ end
+
+ def dummy_response
+ [200, 'dummy_response']
+ end
+
+ end
+end