Skip to content

Commit f4f0265

Browse files
committed
feat: Add ecto_sqlite3 compatibility test suite
- Created support schemas (User, Account, Product, Setting, AccountUser) mirroring ecto_sqlite3 test structure - Added comprehensive integration tests for CRUD, JSON, timestamps, and binary data - Tests adapted from ecto_sqlite3 integration test suite to verify ecto_libsql compatibility - Added test helper modules (Case, Repo, Migration) for test infrastructure - Updated test_helper.exs to load support files and schemas Current status: 21 tests created, RETURNING clause working but ID population from RETURNING needs debugging. Existing ecto_returning_test.exs and type_compatibility_test.exs still pass (3 tests). Tests show: ✅ Timestamps are properly encoded/decoded (inserted_at/updated_at work) ✅ Type compatibility working for existing tests ⚠️ RETURNING ID not populating in shared schema tests - needs investigation
1 parent 011a05a commit f4f0265

14 files changed

Lines changed: 1102 additions & 0 deletions
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
defmodule EctoLibSql.EctoSqlite3BlobCompatTest do
2+
@moduledoc """
3+
Compatibility tests based on ecto_sqlite3 blob test suite.
4+
5+
These tests ensure that binary/blob field handling works identically to ecto_sqlite3.
6+
"""
7+
8+
use EctoLibSql.Integration.Case, async: false
9+
10+
alias EctoLibSql.Integration.TestRepo
11+
alias EctoLibSql.Schemas.Setting
12+
13+
@test_db "z_ecto_libsql_test-sqlite3_blob_compat.db"
14+
15+
setup_all do
16+
# Configure the repo
17+
Application.put_env(:ecto_libsql, EctoLibSql.Integration.TestRepo,
18+
adapter: Ecto.Adapters.LibSql,
19+
database: @test_db
20+
)
21+
22+
{:ok, _} = EctoLibSql.Integration.TestRepo.start_link()
23+
24+
# Run migrations
25+
:ok = Ecto.Migrator.up(
26+
EctoLibSql.Integration.TestRepo,
27+
0,
28+
EctoLibSql.Integration.Migration,
29+
log: false
30+
)
31+
32+
on_exit(fn ->
33+
EctoLibSql.TestHelpers.cleanup_db_files(@test_db)
34+
end)
35+
36+
:ok
37+
end
38+
39+
test "updates blob to nil" do
40+
setting =
41+
%Setting{}
42+
|> Setting.changeset(%{checksum: <<0x00, 0x01>>})
43+
|> TestRepo.insert!()
44+
45+
# Read the record back using ecto and confirm it
46+
assert %Setting{checksum: <<0x00, 0x01>>} =
47+
TestRepo.get(Setting, setting.id)
48+
49+
assert %Setting{checksum: nil} =
50+
setting
51+
|> Setting.changeset(%{checksum: nil})
52+
|> TestRepo.update!()
53+
end
54+
55+
test "inserts and retrieves binary data" do
56+
binary_data = <<1, 2, 3, 4, 5, 255>>
57+
58+
setting =
59+
%Setting{}
60+
|> Setting.changeset(%{checksum: binary_data})
61+
|> TestRepo.insert!()
62+
63+
fetched = TestRepo.get(Setting, setting.id)
64+
assert fetched.checksum == binary_data
65+
end
66+
67+
test "binary data round-trip with various byte values" do
68+
# Test with various byte values including edge cases
69+
binary_data = <<0x00, 0x7F, 0x80, 0xFF, 1, 2, 3>>
70+
71+
setting =
72+
%Setting{}
73+
|> Setting.changeset(%{checksum: binary_data})
74+
|> TestRepo.insert!()
75+
76+
fetched = TestRepo.get(Setting, setting.id)
77+
assert fetched.checksum == binary_data
78+
assert byte_size(fetched.checksum) == byte_size(binary_data)
79+
end
80+
81+
test "updates binary field to new value" do
82+
original = <<0xAA, 0xBB>>
83+
84+
setting =
85+
%Setting{}
86+
|> Setting.changeset(%{checksum: original})
87+
|> TestRepo.insert!()
88+
89+
new_value = <<0x11, 0x22, 0x33>>
90+
91+
{:ok, updated} =
92+
setting
93+
|> Setting.changeset(%{checksum: new_value})
94+
|> TestRepo.update()
95+
96+
fetched = TestRepo.get(Setting, updated.id)
97+
assert fetched.checksum == new_value
98+
end
99+
end

0 commit comments

Comments
 (0)