mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-10 19:54:24 +01:00
Merge branch 'main' into delete-btree-row
This commit is contained in:
@@ -115,10 +115,14 @@ def validate_string_uuid(result):
|
||||
return len(result) == 36 and result.count("-") == 4
|
||||
|
||||
|
||||
def returns_error(result):
|
||||
def returns_error_no_func(result):
|
||||
return "error: no such function: " in result
|
||||
|
||||
|
||||
def returns_vtable_parse_err(result):
|
||||
return "Parse error: Virtual table" in result
|
||||
|
||||
|
||||
def returns_null(result):
|
||||
return result == "" or result == "\n"
|
||||
|
||||
@@ -167,7 +171,7 @@ def test_regexp(pipe):
|
||||
extension_path = "./target/debug/liblimbo_regexp.so"
|
||||
|
||||
# before extension loads, assert no function
|
||||
run_test(pipe, "SELECT regexp('a.c', 'abc');", returns_error)
|
||||
run_test(pipe, "SELECT regexp('a.c', 'abc');", returns_error_no_func)
|
||||
run_test(pipe, f".load {extension_path}", returns_null)
|
||||
print(f"Extension {extension_path} loaded successfully.")
|
||||
run_test(pipe, "SELECT regexp('a.c', 'abc');", validate_true)
|
||||
@@ -214,7 +218,7 @@ def test_aggregates(pipe):
|
||||
run_test(
|
||||
pipe,
|
||||
"SELECT median(1);",
|
||||
returns_error,
|
||||
returns_error_no_func,
|
||||
"median agg function returns null when ext not loaded",
|
||||
)
|
||||
run_test(
|
||||
@@ -256,12 +260,208 @@ def test_aggregates(pipe):
|
||||
)
|
||||
|
||||
|
||||
# Encoders and decoders
|
||||
def validate_url_encode(a):
|
||||
return a == "%2Fhello%3Ftext%3D%28%E0%B2%A0_%E0%B2%A0%29"
|
||||
|
||||
|
||||
def validate_url_decode(a):
|
||||
return a == "/hello?text=(ಠ_ಠ)"
|
||||
|
||||
|
||||
def validate_hex_encode(a):
|
||||
return a == "68656c6c6f"
|
||||
|
||||
|
||||
def validate_hex_decode(a):
|
||||
return a == "hello"
|
||||
|
||||
|
||||
def validate_base85_encode(a):
|
||||
return a == "BOu!rDZ"
|
||||
|
||||
|
||||
def validate_base85_decode(a):
|
||||
return a == "hello"
|
||||
|
||||
|
||||
def validate_base32_encode(a):
|
||||
return a == "NBSWY3DP"
|
||||
|
||||
|
||||
def validate_base32_decode(a):
|
||||
return a == "hello"
|
||||
|
||||
|
||||
def validate_base64_encode(a):
|
||||
return a == "aGVsbG8="
|
||||
|
||||
|
||||
def validate_base64_decode(a):
|
||||
return a == "hello"
|
||||
|
||||
|
||||
def test_crypto(pipe):
|
||||
extension_path = "./target/debug/liblimbo_crypto.so"
|
||||
# assert no function before extension loads
|
||||
run_test(
|
||||
pipe,
|
||||
"SELECT crypto_blake('a');",
|
||||
lambda res: "Parse error" in res,
|
||||
"crypto_blake3 returns null when ext not loaded",
|
||||
)
|
||||
run_test(
|
||||
pipe,
|
||||
f".load {extension_path}",
|
||||
returns_null,
|
||||
"load extension command works properly",
|
||||
)
|
||||
# Hashing and Decode
|
||||
run_test(
|
||||
pipe,
|
||||
"SELECT crypto_encode(crypto_blake3('abc'), 'hex');",
|
||||
lambda res: res
|
||||
== "6437b3ac38465133ffb63b75273a8db548c558465d79db03fd359c6cd5bd9d85",
|
||||
"blake3 should encrypt correctly",
|
||||
)
|
||||
run_test(
|
||||
pipe,
|
||||
"SELECT crypto_encode(crypto_md5('abc'), 'hex');",
|
||||
lambda res: res == "900150983cd24fb0d6963f7d28e17f72",
|
||||
"md5 should encrypt correctly",
|
||||
)
|
||||
run_test(
|
||||
pipe,
|
||||
"SELECT crypto_encode(crypto_sha1('abc'), 'hex');",
|
||||
lambda res: res == "a9993e364706816aba3e25717850c26c9cd0d89d",
|
||||
"sha1 should encrypt correctly",
|
||||
)
|
||||
run_test(
|
||||
pipe,
|
||||
"SELECT crypto_encode(crypto_sha256('abc'), 'hex');",
|
||||
lambda a: a
|
||||
== "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
|
||||
"sha256 should encrypt correctly",
|
||||
)
|
||||
run_test(
|
||||
pipe,
|
||||
"SELECT crypto_encode(crypto_sha384('abc'), 'hex');",
|
||||
lambda a: a
|
||||
== "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7",
|
||||
"sha384 should encrypt correctly",
|
||||
)
|
||||
run_test(
|
||||
pipe,
|
||||
"SELECT crypto_encode(crypto_sha512('abc'), 'hex');",
|
||||
lambda a: a
|
||||
== "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f",
|
||||
"sha512 should encrypt correctly",
|
||||
)
|
||||
|
||||
# Encoding and Decoding
|
||||
run_test(
|
||||
pipe,
|
||||
"SELECT crypto_encode('hello', 'base32');",
|
||||
validate_base32_encode,
|
||||
"base32 should encode correctly",
|
||||
)
|
||||
run_test(
|
||||
pipe,
|
||||
"SELECT crypto_decode('NBSWY3DP', 'base32');",
|
||||
validate_base32_decode,
|
||||
"base32 should decode correctly",
|
||||
)
|
||||
run_test(
|
||||
pipe,
|
||||
"SELECT crypto_encode('hello', 'base64');",
|
||||
validate_base64_encode,
|
||||
"base64 should encode correctly",
|
||||
)
|
||||
run_test(
|
||||
pipe,
|
||||
"SELECT crypto_decode('aGVsbG8=', 'base64');",
|
||||
validate_base64_decode,
|
||||
"base64 should decode correctly",
|
||||
)
|
||||
run_test(
|
||||
pipe,
|
||||
"SELECT crypto_encode('hello', 'base85');",
|
||||
validate_base85_encode,
|
||||
"base85 should encode correctly",
|
||||
)
|
||||
run_test(
|
||||
pipe,
|
||||
"SELECT crypto_decode('BOu!rDZ', 'base85');",
|
||||
validate_base85_decode,
|
||||
"base85 should decode correctly",
|
||||
)
|
||||
|
||||
run_test(
|
||||
pipe,
|
||||
"SELECT crypto_encode('hello', 'hex');",
|
||||
validate_hex_encode,
|
||||
"hex should encode correctly",
|
||||
)
|
||||
run_test(
|
||||
pipe,
|
||||
"SELECT crypto_decode('68656c6c6f', 'hex');",
|
||||
validate_hex_decode,
|
||||
"hex should decode correctly",
|
||||
)
|
||||
|
||||
run_test(
|
||||
pipe,
|
||||
"SELECT crypto_encode('/hello?text=(ಠ_ಠ)', 'url');",
|
||||
validate_url_encode,
|
||||
"url should encode correctly",
|
||||
)
|
||||
run_test(
|
||||
pipe,
|
||||
"SELECT crypto_decode('%2Fhello%3Ftext%3D%28%E0%B2%A0_%E0%B2%A0%29', 'url');",
|
||||
validate_url_decode,
|
||||
"url should decode correctly",
|
||||
)
|
||||
|
||||
|
||||
def test_series(pipe):
|
||||
ext_path = "./target/debug/liblimbo_series"
|
||||
run_test(
|
||||
pipe,
|
||||
"SELECT * FROM generate_series(1, 10);",
|
||||
lambda res: "Virtual table generate_series not found" in res,
|
||||
)
|
||||
run_test(pipe, f".load {ext_path}", returns_null)
|
||||
run_test(
|
||||
pipe,
|
||||
"SELECT * FROM generate_series(1, 10);",
|
||||
lambda res: "Invalid Argument" in res,
|
||||
)
|
||||
run_test(
|
||||
pipe,
|
||||
"SELECT * FROM generate_series(1, 10, 2);",
|
||||
lambda res: res == "1\n3\n5\n7\n9",
|
||||
)
|
||||
run_test(
|
||||
pipe,
|
||||
"SELECT * FROM generate_series(1, 10, 2, 3);",
|
||||
lambda res: "Invalid Argument" in res,
|
||||
)
|
||||
run_test(
|
||||
pipe,
|
||||
"SELECT * FROM generate_series(10, 1, -2);",
|
||||
lambda res: res == "10\n8\n6\n4\n2",
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
pipe = init_limbo()
|
||||
try:
|
||||
test_regexp(pipe)
|
||||
test_uuid(pipe)
|
||||
test_aggregates(pipe)
|
||||
test_crypto(pipe)
|
||||
test_series(pipe)
|
||||
|
||||
except Exception as e:
|
||||
print(f"Test FAILED: {e}")
|
||||
pipe.terminate()
|
||||
|
||||
Reference in New Issue
Block a user