@@ -3,6 +3,15 @@ defmodule Ecto.Adapters.SQLite3Test do
3
3
4
4
alias Ecto.Adapters.SQLite3
5
5
6
+ @ uuid_regex ~R/ ^[[:xdigit:]]{8}\b-[[:xdigit:]]{4}\b-[[:xdigit:]]{4}\b-[[:xdigit:]]{4}\b-[[:xdigit:]]{12}$/
7
+
8
+ setup do
9
+ original_binary_id_type = Application . get_env ( :ecto_sqlite3 , :binary_id_type )
10
+ on_exit ( fn ->
11
+ Application . put_env ( :ecto_sqlite3 , :binary_id_type , original_binary_id_type )
12
+ end )
13
+ end
14
+
6
15
describe ".storage_up/1" do
7
16
test "create database" do
8
17
opts = [ database: Temp . path! ( ) ]
@@ -51,4 +60,27 @@ defmodule Ecto.Adapters.SQLite3Test do
51
60
File . rm ( opts [ :database ] )
52
61
end
53
62
end
63
+
64
+ describe ".autogenerate/1" do
65
+ test ":id must be generated from storage" do
66
+ assert SQLite3 . autogenerate ( :id ) == nil
67
+ end
68
+
69
+ test ":embed_id is a UUID in string form" do
70
+ assert string_uuid? ( SQLite3 . autogenerate ( :embed_id ) )
71
+ end
72
+
73
+ test ":binary_id with type :string is a UUID in string form" do
74
+ Application . put_env ( :ecto_sqlite3 , :binary_id_type , :string )
75
+ assert string_uuid? ( SQLite3 . autogenerate ( :binary_id ) )
76
+ end
77
+
78
+ test ":binary_id with type :binary is a UUID in binary form" do
79
+ Application . put_env ( :ecto_sqlite3 , :binary_id_type , :binary )
80
+ assert binary_uuid? ( SQLite3 . autogenerate ( :binary_id ) )
81
+ end
82
+ end
83
+
84
+ defp string_uuid? ( uuid ) , do: Regex . match? ( @ uuid_regex , uuid )
85
+ defp binary_uuid? ( uuid ) , do: bit_size ( uuid ) == 128
54
86
end
0 commit comments