-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathresolvers_test.go
More file actions
89 lines (69 loc) · 1.59 KB
/
resolvers_test.go
File metadata and controls
89 lines (69 loc) · 1.59 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package submodule
import (
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
var intValue = Make[int](func() int {
return 100
})
var anyValue = Make[any](func(v any) any {
return v
}, intValue)
var stringValue = Make[string](func() string {
return "hello"
})
type Embedded struct {
In
Int int
String string
}
func TestResolver(t *testing.T) {
t.Run("can resolve type", func(t *testing.T) {
store := CreateScope()
r, e := resolveType(store, reflect.TypeOf(0), []Retrievable{intValue})
assert.Nil(t, e)
assert.Equal(t, r.Interface(), 100)
r, e = resolveType(
store,
reflect.TypeOf(Embedded{}),
[]Retrievable{intValue, stringValue},
)
v, ok := r.Interface().(Embedded)
assert.True(t, ok)
assert.Nil(t, e)
assert.Equal(t, 100, v.Int)
assert.Equal(t, "hello", v.String)
})
t.Run("can resolve type", func(t *testing.T) {
store := CreateScope()
anyValue.ResolveWith(store)
})
t.Run("can resolve embedded type", func(t *testing.T) {
store := CreateScope()
var v Embedded
_, e := resolveEmbedded(
store,
reflect.TypeOf(Embedded{}),
reflect.ValueOf(&v),
[]Retrievable{intValue, stringValue},
)
assert.Nil(t, e)
assert.Equal(t, v.Int, 100)
assert.Equal(t, v.String, "hello")
})
t.Run("value can be replaced", func(t *testing.T) {
store := CreateScope()
store.InitValue(intValue, 200)
var v Embedded
_, e := resolveEmbedded(
store,
reflect.TypeOf(Embedded{}),
reflect.ValueOf(&v),
[]Retrievable{intValue, stringValue},
)
assert.Nil(t, e)
assert.Equal(t, v.Int, 200)
assert.Equal(t, v.String, "hello")
})
}