-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathtest_helper.exs
More file actions
42 lines (37 loc) · 1.24 KB
/
test_helper.exs
File metadata and controls
42 lines (37 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
defmodule Tds.TestHelper do
require Logger
defmacro query(statement, params, opts \\ []) do
quote do
case Tds.query(var!(context)[:pid], unquote(statement),
unquote(params), unquote(opts)) do
{:ok, %Tds.Result{rows: nil}} -> :ok
{:ok, %Tds.Result{rows: []}} -> :ok
{:ok, %Tds.Result{rows: rows}} -> rows
{:error, %Tds.Error{} = err} -> err
end
end
end
defmacro proc(proc, params, opts \\ []) do
quote do
case Tds.proc(var!(context)[:pid], unquote(proc),
unquote(params), unquote(opts)) do
{:ok, %Tds.Result{rows: nil}} -> :ok
{:ok, %Tds.Result{rows: []}} -> :ok
{:ok, %Tds.Result{rows: rows}} -> rows
{:error, %Tds.Error{} = err} -> err
end
end
end
def sqlcmd(params, sql, args \\ []) do
args = [
"-U", params[:username],
"-P", params[:password],
"-S", params[:hostname],
"-Q", ~s(#{sql}) | args]
System.cmd "sqlcmd", args
end
end
Application.get_env(:tds, :opts)
|> Tds.TestHelper.sqlcmd("IF NOT EXISTS(SELECT * FROM sys.databases where name = 'test') BEGIN CREATE DATABASE [test]; END;")
ExUnit.start()
ExUnit.configure exclude: [:manual]