-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhelpers_test.go
65 lines (57 loc) · 1.1 KB
/
helpers_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package goseeder
import (
"github.com/stretchr/testify/require"
"testing"
)
func TestFindString(t *testing.T) {
input := []string{
"dandy",
"trout",
"fish",
"more",
"fish",
"ok",
}
pos, found := findString(input, "fish")
require.Equal(t, 2, pos)
require.Equal(t, true, found)
}
func TestPrepareStatement(t *testing.T) {
table := "categories"
data := map[string]string{
"id": "100",
"name": "common",
}
sb, args := prepareStatement(table, data)
require.Equal(
t,
"insert into categories (id, name) values (?, ?)",
sb.String(),
)
require.Equal(
t,
[]interface{}{
int64(100),
"common"},
args,
)
}
var testCases = []struct {
name string
value string
expected interface{}
}{
{"bool", "true", true},
{"bool", "false", false},
{"int", "12", int64(12)},
{"float", "12.77", 12.770000457763672},
{"string", "justastring", "justastring"},
{"string_with_nr", "12justastring", "12justastring"},
}
func TestParseValue(t *testing.T) {
for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
require.Equal(t, tt.expected, parseValue(tt.value))
})
}
}