-
Notifications
You must be signed in to change notification settings - Fork 27
/
main_test.go
executable file
·83 lines (70 loc) · 1.8 KB
/
main_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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"github.com/linkpoolio/bridges"
"github.com/stretchr/testify/assert"
"testing"
)
func TestAPIAggregator_Run(t *testing.T) {
aggregationTypes := []string{
"", "mean", "median", "mode", "nonexistent",
}
aa := APIAggregator{}
for _, at := range aggregationTypes {
t.Run(at, func(t *testing.T) {
p := map[string]interface{}{
"api": []string{
"https://www.binance.com/api/v3/ticker/price?symbol=BTCUSDT",
"https://api.pro.coinbase.com/products/btc-usd/ticker",
},
"paths": []string{
"$.price",
"$.price",
},
"type": at,
}
json, err := bridges.ParseInterface(p)
assert.Nil(t, err)
h := bridges.NewHelper(json)
obj, err := aa.Run(h)
assert.Nil(t, err)
r, ok := obj.(Result)
assert.True(t, ok)
assert.True(t, len(r.AggregateValue) != 0)
assert.True(t, len(r.APIErrors) == 0)
assert.Equal(t, r.AggregationType, at)
})
}
}
func TestFetch_EmptyParam(t *testing.T) {
p := map[string]interface{}{}
aa := APIAggregator{}
json, err := bridges.ParseInterface(p)
assert.Nil(t, err)
h := bridges.NewHelper(json)
_, err = aa.Run(h)
assert.Equal(t, err.Error(), "Invalid api and path array")
}
func TestFetch_InvalidArray(t *testing.T) {
p := map[string]interface{}{
"api": []string{
"https://www.binance.com/api/v3/ticker/price?symbol=BTCUSDT",
"https://api.pro.coinbase.com/products/btc-usd/ticker",
},
"paths": []string{
"$.last",
},
"type": "mode",
}
aa := APIAggregator{}
json, err := bridges.ParseInterface(p)
assert.Nil(t, err)
h := bridges.NewHelper(json)
_, err = aa.Run(h)
assert.Equal(t, err.Error(), "Invalid api and path array")
}
func TestCryptoCompare_Opts(t *testing.T) {
cc := APIAggregator{}
opts := cc.Opts()
assert.Equal(t, opts.Name, "APIAggregator")
assert.True(t, opts.Lambda)
}