generated from sensu/check-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsql_test.go
46 lines (43 loc) · 984 Bytes
/
sql_test.go
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
package main
import (
"bytes"
"database/sql"
"testing"
)
func TestMetricsDDL(t *testing.T) {
columnNames := []string{"one", "two", "three", "four"}
var buf bytes.Buffer
if err := metricsDDLTmpl.Execute(&buf, columnNames); err != nil {
t.Fatal(err)
}
db, err := sql.Open("sqlite", ":memory:")
if err != nil {
t.Fatal(err)
}
defer db.Close()
if _, err := db.Exec(buf.String()); err != nil {
t.Fatal(err)
}
}
func TestInsertMetrics(t *testing.T) {
columnNames := []string{"one", "two", "three", "four"}
var buf bytes.Buffer
if err := metricsDDLTmpl.Execute(&buf, columnNames); err != nil {
t.Fatal(err)
}
db, err := sql.Open("sqlite", ":memory:")
if err != nil {
t.Fatal(err)
}
defer db.Close()
if _, err := db.Exec(buf.String()); err != nil {
t.Fatal(err)
}
buf.Reset()
if err := insertMetricTmpl.Execute(&buf, columnNames); err != nil {
t.Fatal(err)
}
if _, err := db.Exec(buf.String(), "1", "2", "3", "4"); err != nil {
t.Fatal(err)
}
}