|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +class UniversalID::Packer::ActiveSupportCacheStoreTest < Minitest::Test |
| 4 | + def test_pack_unpack |
| 5 | + expected = ActiveSupport::Cache::MemoryStore.new |
| 6 | + scalars.each { |key, val| expected.write key, val, expires_in: 1.second } |
| 7 | + packed = UniversalID::Packer.pack(expected) |
| 8 | + actual = UniversalID::Packer.unpack(packed) |
| 9 | + assert_active_support_cache_store expected, actual, expires_in: 1.second |
| 10 | + end |
| 11 | +end |
| 12 | + |
| 13 | +class UniversalID::Encoder::ActiveSupportCacheStoreTest < Minitest::Test |
| 14 | + def test_encode_decode |
| 15 | + expected = ActiveSupport::Cache::MemoryStore.new |
| 16 | + scalars.each { |key, val| expected.write key, val, expires_in: 1.second } |
| 17 | + encoded = UniversalID::Encoder.encode(expected) |
| 18 | + actual = UniversalID::Encoder.decode(encoded) |
| 19 | + assert_active_support_cache_store expected, actual, expires_in: 1.second |
| 20 | + end |
| 21 | +end |
| 22 | + |
| 23 | +class URI::UID::ActiveSupportCacheStoreTest < Minitest::Test |
| 24 | + def test_build_parse_decode |
| 25 | + expected = ActiveSupport::Cache::MemoryStore.new |
| 26 | + scalars.each { |key, val| expected.write key, val, expires_in: 1.second } |
| 27 | + uri = URI::UID.build(expected).to_s |
| 28 | + actual = URI::UID.parse(uri).decode |
| 29 | + assert_active_support_cache_store expected, actual, expires_in: 1.second |
| 30 | + end |
| 31 | + |
| 32 | + def test_global_id |
| 33 | + expected = ActiveSupport::Cache::MemoryStore.new |
| 34 | + scalars.each { |key, val| expected.write key, val, expires_in: 1.second } |
| 35 | + gid = URI::UID.build(expected).to_gid_param |
| 36 | + actual = URI::UID.from_gid(gid).decode |
| 37 | + assert_active_support_cache_store expected, actual, expires_in: 1.second |
| 38 | + end |
| 39 | + |
| 40 | + def test_signed_global_id |
| 41 | + expected = ActiveSupport::Cache::MemoryStore.new |
| 42 | + scalars.each { |key, val| expected.write key, val, expires_in: 1.second } |
| 43 | + sgid = URI::UID.build(expected).to_sgid_param |
| 44 | + actual = URI::UID.from_sgid(sgid).decode |
| 45 | + assert_active_support_cache_store expected, actual, expires_in: 1.second |
| 46 | + end |
| 47 | +end |
0 commit comments