-
Notifications
You must be signed in to change notification settings - Fork 2
/
helpers_test.go
69 lines (61 loc) · 1.23 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
66
67
68
69
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]interface{}{
"id": "100",
"name": "common",
}
sb, args := prepareStatement(table, data)
require.Equal(
t,
"insert into categories (id, name) values (?, ?)",
sb.String(),
)
require.Equal(
t,
[]interface{}{
"100",
"common"},
args,
)
}
var testCases = []struct {
name string
value interface{}
expected interface{}
}{
{"bool_string", "true", "true"},
{"bool_true", true, true},
{"bool_string", "false", "false"},
{"bool_false", false, false},
{"int_string", "12", "12"},
{"int", 12, int(12)},
{"float_string", "12.77", "12.77"},
{"float", 12.77, 12.77},
{"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))
})
}
}