mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 17:13:51 +00:00
31 lines
537 B
Go
31 lines
537 B
Go
|
package bbgo
|
||
|
|
||
|
import (
|
||
|
"reflect"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
|
||
|
"github.com/c9s/bbgo/pkg/service"
|
||
|
)
|
||
|
|
||
|
func Test_injectField(t *testing.T) {
|
||
|
type TT struct {
|
||
|
TradeService *service.TradeService
|
||
|
}
|
||
|
|
||
|
// only pointer object can be set.
|
||
|
var tt = &TT{}
|
||
|
|
||
|
// get the value of the pointer, or it can not be set.
|
||
|
var rv = reflect.ValueOf(tt).Elem()
|
||
|
|
||
|
_, ret := hasField(rv, "TradeService")
|
||
|
assert.True(t, ret)
|
||
|
|
||
|
ts := &service.TradeService{}
|
||
|
|
||
|
err := injectField(rv, "TradeService", ts, true)
|
||
|
assert.NoError(t, err)
|
||
|
}
|