File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change
1
+ package internal
2
+
3
+ import (
4
+ "github.com/stretchr/testify/assert"
5
+ "reflect"
6
+ "testing"
7
+ )
8
+
9
+ const unexportedField = "unexported"
10
+
11
+ type Foo struct {
12
+ unexported string
13
+ }
14
+
15
+ func TestGetUnexportedField (t * testing.T ) {
16
+ foo := & Foo {unexported : "x" }
17
+ value := GetUnexportedField (reflect .ValueOf (foo ).Elem ().FieldByName (unexportedField ))
18
+ assert .Equal (t , value , "x" )
19
+ }
20
+
21
+ func TestSetUnexportedField (t * testing.T ) {
22
+ foo := & Foo {unexported : "old" }
23
+ SetUnexportedField (reflect .ValueOf (foo ).Elem ().FieldByName (unexportedField ), "changed" )
24
+ assert .Equal (t , foo .unexported , "changed" )
25
+ }
26
+
27
+ func TestSetFieldValue (t * testing.T ) {
28
+ foo := & Foo {unexported : "old" }
29
+ SetFieldValue (reflect .ValueOf (foo ).Elem (), 0 , "changed" )
30
+ assert .Equal (t , foo .unexported , "changed" )
31
+ }
You can’t perform that action at this time.
0 commit comments