-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetPrivateValue_test.go
69 lines (52 loc) · 1.36 KB
/
setPrivateValue_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 testingtools
import (
"fmt"
"testing"
"github.com/dedalqq/omg.testingtools/testmodule"
)
func TestSetPrivateValue(t *testing.T) {
qq := testmodule.NewTestStruct(true, 123, "abc", []int{5, 6, 7})
SetPrivateValue(&qq, "a", false)
SetPrivateValue(&qq, "d", []int{1, 2, 3, 4})
SetPrivateValue(&qq, "c", "qwe")
if fmt.Sprint(qq) != "{false 123 qwe [1 2 3 4]}" {
t.Fail()
}
}
func TestNotPointerError(t *testing.T) {
defer func() {
if r := recover(); r != "object is not a pointer" {
t.Fail()
}
}()
qq := testmodule.NewTestStruct(true, 123, "abc", []int{5, 6, 7})
SetPrivateValue(qq, "a", false)
}
func TestNotStructError(t *testing.T) {
defer func() {
if r := recover(); r != "object is not a pointer to struct" {
fmt.Println(r)
t.Fail()
}
}()
notObject := "string"
SetPrivateValue(¬Object, "a", false)
}
func TestIncorrectValueTypeError(t *testing.T) {
defer func() {
if r := recover(); r != "incorrect type: must be []int" {
t.Fail()
}
}()
qq := testmodule.NewTestStruct(true, 123, "abc", []int{5, 6, 7})
SetPrivateValue(&qq, "d", []byte{5, 6, 7})
}
func TestIncorrectFieldNameError(t *testing.T) {
defer func() {
if r := recover(); r != "Field [incorrectValue] not found in struct" {
t.Fail()
}
}()
qq := testmodule.NewTestStruct(true, 123, "abc", []int{5, 6, 7})
SetPrivateValue(&qq, "incorrectValue", false)
}