-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper_test.go
48 lines (42 loc) · 1.01 KB
/
helper_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
package rabbit
import (
"strconv"
"testing"
"github.com/stretchr/testify/assert"
)
type testMapForm struct {
ID uint `json:"id" binding:"required"`
Title *string `json:"title"`
Source *string `json:"source"`
}
func TestFormAsMap(t *testing.T) {
title := "title"
form := testMapForm{
ID: 100,
Title: &title,
}
{
vals := StructAsMap(form, []string{"Title", "Target"}) // Title is valid
assert.Equal(t, 1, len(vals))
assert.Equal(t, title, vals["Title"])
}
{
vals := StructAsMap(form, []string{"ID", "Source"}) // ID is valid
assert.Equal(t, 1, len(vals))
assert.Equal(t, uint(100), vals["ID"])
}
{
vals := StructAsMap(&form, []string{"ID", "Title"}) // ID, Title are valid
assert.Equal(t, 2, len(vals))
assert.Equal(t, uint(100), vals["ID"])
assert.Equal(t, title, vals["Title"])
}
}
func TestRandText(t *testing.T) {
v := RandText(10)
assert.Equal(t, len(v), 10)
v2 := RandNumberText(5)
assert.Equal(t, len(v2), 5)
_, err := strconv.ParseInt(v2, 10, 64)
assert.Nil(t, err)
}