-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegration_test.go
More file actions
92 lines (79 loc) · 1.87 KB
/
integration_test.go
File metadata and controls
92 lines (79 loc) · 1.87 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright (c) 2019, Mohlmann Solutions SRL. All rights reserved.
// Use of this source code is governed by a License that can be found in the LICENSE file.
// SPDX-License-Identifier: BSD-3-Clause
package main
import (
"os"
"testing"
)
const (
dropCategoriesQuery = "drop table if exists categories cascade;"
createCategoriesQuery = `create table categories (
id int primary key,
label varchar(100)
);`
dropArticlesQuery = "drop table if exists articles cascade;"
createArticlesQuery = `create table articles (
id bigint primary key,
created timestamp,
title varchar(100),
description varchar(2000),
category_id int references categories (id),
published bool not null,
price decimal null,
score real null
);`
)
func prepSqliteTest() error {
os.Remove("test.db")
db, err := exampleSchemas["sqlite"].connect()
if err != nil {
return err
}
defer db.Close()
if _, err := db.Exec(createCategoriesQuery); err != nil {
return err
}
if _, err := db.Exec(createArticlesQuery); err != nil {
return err
}
return nil
}
func TestRunSqlite(t *testing.T) {
if err := prepSqliteTest(); err != nil {
t.Fatal(err)
}
schemaFile = "example_sqlite.json"
if ret := run(); ret != 0 {
t.Errorf("run() ret = %v, wantRet %v", ret, 0)
}
}
func prepPqTest() error {
db, err := exampleSchemas["pq"].connect()
if err != nil {
return err
}
defer db.Close()
if _, err := db.Exec(dropArticlesQuery); err != nil {
return err
}
if _, err := db.Exec(dropCategoriesQuery); err != nil {
return err
}
if _, err := db.Exec(createCategoriesQuery); err != nil {
return err
}
if _, err := db.Exec(createArticlesQuery); err != nil {
return err
}
return nil
}
func TestRunPq(t *testing.T) {
if err := prepPqTest(); err != nil {
t.Fatal(err)
}
schemaFile = "example_pq.json"
if ret := run(); ret != 0 {
t.Errorf("run() ret = %v, wantRet %v", ret, 0)
}
}