Skip to content
This repository was archived by the owner on Mar 19, 2021. It is now read-only.

Commit 380ced6

Browse files
Alex GolubovConnorRigby
authored andcommitted
Increase code coverage by tests
1 parent e610a8e commit 380ced6

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

test/statement_test.exs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,73 @@ defmodule Sqlitex.StatementTest do
104104

105105
assert reason == :timeout
106106
end
107+
108+
test "prepare! raise" do
109+
{:ok, db} = Sqlitex.open(":memory:")
110+
111+
assert_raise Sqlitex.Statement.PrepareError, fn ->
112+
Sqlitex.Statement.prepare!(db, "SELECT * FROMMMM TABLE;")
113+
end
114+
end
115+
116+
test "build_values error" do
117+
{:ok, db} = Sqlitex.open(":memory:")
118+
119+
:ok = Sqlitex.exec(db, "CREATE TABLE bv (id INTEGER PRIMARY KEY);")
120+
121+
result = db
122+
|> Sqlitex.Statement.prepare!("SELECT * FROM bv")
123+
|> Sqlitex.Statement.bind_values([1])
124+
125+
assert result == {:error, :args_wrong_length}
126+
end
127+
128+
test "build_values! ok" do
129+
{:ok, db} = Sqlitex.open(":memory:")
130+
131+
:ok = Sqlitex.exec(db, "CREATE TABLE bv (id INTEGER PRIMARY KEY);")
132+
133+
assert {:ok, _stmt} = db
134+
|> Sqlitex.Statement.prepare!("SELECT * FROM bv WHERE id = ?1")
135+
|> Sqlitex.Statement.bind_values([1])
136+
end
137+
138+
test "build_values! raise" do
139+
{:ok, db} = Sqlitex.open(":memory:")
140+
141+
:ok = Sqlitex.exec(db, "CREATE TABLE bv (id INTEGER PRIMARY KEY);")
142+
143+
assert_raise Sqlitex.Statement.BindValuesError, fn ->
144+
db
145+
|> Sqlitex.Statement.prepare!("SELECT * FROM bv")
146+
|> Sqlitex.Statement.bind_values!([1])
147+
end
148+
end
149+
150+
test "fetch_all! raise" do
151+
{:ok, db} = Sqlitex.open(":memory:")
152+
153+
:ok = Sqlitex.exec(db, "CREATE TABLE bv (id INTEGER PRIMARY KEY);")
154+
:ok = Sqlitex.exec(db, "BEGIN TRANSACTION;")
155+
156+
assert_raise Sqlitex.Statement.FetchAllError, fn ->
157+
db
158+
|> Sqlitex.Statement.prepare!("BEGIN TRANSACTION;")
159+
|> Sqlitex.Statement.fetch_all!(db_timeout: 1_000)
160+
end
161+
end
162+
163+
test "exec! raise" do
164+
{:ok, db} = Sqlitex.open(":memory:")
165+
166+
:ok = Sqlitex.exec(db, "CREATE TABLE bv (id INTEGER PRIMARY KEY);")
167+
:ok = Sqlitex.exec(db, "BEGIN TRANSACTION;")
168+
169+
assert_raise Sqlitex.Statement.ExecError, fn ->
170+
db
171+
|> Sqlitex.Statement.prepare!("BEGIN TRANSACTION;")
172+
|> Sqlitex.Statement.exec!(db_timeout: 1_000)
173+
end
174+
end
175+
107176
end

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy