telega/testing/storage

The contract every KeyValueStorage backend has to meet, as one function a backend’s test suite calls.

import telega/testing/storage as storage_contract

pub fn satisfies_the_storage_contract_test() {
  storage_contract.check(my_backend, prefix: "contract:")
}

check panics with the clause that failed. It only touches keys starting with prefix and deletes them again, so it is safe against a shared database as long as the prefix is this suite’s own.

Values

pub fn check(
  kv: storage.KeyValueStorage(error),
  prefix prefix: String,
) -> Nil

Exercise kv: get on a missing key, set/get/overwrite/delete, a literal scan prefix (no _, %, * or ? wildcards) that pages to completion, TTL expiry, and compare_and_set against an absent, a present, a differing and an expired value.

✨ Search Document