summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2018-01-15 18:21:44 +0100
committerAzul <azul@riseup.net>2018-01-18 16:43:23 +0100
commitb8ba4f27a82868e0b3338b4af761f7c44226e729 (patch)
tree45b495e18bab72508342b86cd42ab3d56ed1eacc /test
parentfd2fc85c2daf60605641cc582d75134a10e7b4a4 (diff)
(WIP) first steps towards implementing keys API
Diffstat (limited to 'test')
-rw-r--r--test/unit/keyring_test.rb60
1 files changed, 60 insertions, 0 deletions
diff --git a/test/unit/keyring_test.rb b/test/unit/keyring_test.rb
new file mode 100644
index 0000000..059b8dd
--- /dev/null
+++ b/test/unit/keyring_test.rb
@@ -0,0 +1,60 @@
+require 'test_helper'
+
+class KeyringTest < ActiveSupport::TestCase
+
+ test 'create initial key' do
+ keyring.create 'type', 'value'
+ assert_equal 'value', keyring.key_of_type('type')['value']
+ end
+
+ test 'raise on creating twice' do
+ keyring.create 'type', 'value'
+ assert_raises Keyring::Error do
+ keyring.create 'type', 'value'
+ end
+ end
+
+ test 'update with new key' do
+ keyring.create 'type', 'value'
+ initial_rev = keyring.key_of_type('type')['rev']
+ keyring.update 'type', rev: initial_rev, value: 'new value'
+ assert_equal 'new value', keyring.key_of_type('type')['value']
+ end
+
+ test 'raise on updating without rev' do
+ keyring.create 'type', 'value'
+ assert_raises Keyring::Error do
+ keyring.update 'type', rev: nil ,value: 'new value'
+ end
+ assert_equal 'value', keyring.key_of_type('type')['value']
+ end
+
+ test 'raise on updating with wrong rev' do
+ keyring.create 'type', 'value'
+ assert_raises Keyring::Error do
+ keyring.update 'type', rev: 'wrong rev', value: 'new value'
+ end
+ assert_equal 'value', keyring.key_of_type('type')['value']
+ end
+
+
+ protected
+
+ def keyring
+ @keyring ||= Keyring.new(teststorage)
+ end
+
+ def teststorage
+ @teststorage ||= Hash.new.tap do |dummy|
+ def dummy.set_key(type, value)
+ self[type] = value
+ end
+
+ def dummy.keys
+ self
+ end
+
+ def dummy.save; end
+ end
+ end
+end