forked from preichenberger/go-coinbasepro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_helper.go
54 lines (42 loc) · 1.09 KB
/
test_helper.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
package coinbase
import (
"errors"
"fmt"
"os"
"reflect"
)
func NewTestClient() *Client {
secret := os.Getenv("TEST_COINBASE_SECRET")
key := os.Getenv("TEST_COINBASE_KEY")
passphrase := os.Getenv("TEST_COINBASE_PASSPHRASE")
return &Client{
BaseURL: "https://api.gdax.com",
Secret: secret,
Key: key,
Passphrase: passphrase,
}
return NewClient(secret, key, passphrase)
}
func StructHasZeroValues(i interface{}) bool {
iv := reflect.ValueOf(i)
//values := make([]interface{}, v.NumField())
for i := 0; i < iv.NumField(); i++ {
field := iv.Field(i)
if reflect.Zero(field.Type()) == field {
return true
}
}
return false
}
func CompareProperties(a, b interface{}, properties []string) (bool, error) {
aValueOf := reflect.ValueOf(a)
bValueOf := reflect.ValueOf(b)
for _, property := range properties {
aValue := reflect.Indirect(aValueOf).FieldByName(property).Interface()
bValue := reflect.Indirect(bValueOf).FieldByName(property).Interface()
if aValue != bValue {
return false, errors.New(fmt.Sprintf("%s not equal", property))
}
}
return true, nil
}