forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
root_test.go
104 lines (94 loc) · 2.96 KB
/
root_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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package horizonclient
import (
"testing"
"github.com/stellar/go/support/http/httptest"
"github.com/stretchr/testify/assert"
)
func TestRoot(t *testing.T) {
hmock := httptest.NewClient()
client := &Client{
HorizonURL: "https://localhost/",
HTTP: hmock,
}
// happy path
hmock.On(
"GET",
"https://localhost/",
).ReturnString(200, rootResponse)
root, err := client.Root()
if assert.NoError(t, err) {
assert.Equal(t, root.HorizonVersion, "0.17.6-unstable-bc999a67d0b2413d8abd76153a56733c7d517484")
assert.Equal(t, root.StellarCoreVersion, "stellar-core 11.0.0 (236f831521b6724c0ae63906416faa997ef27e19)")
assert.Equal(t, root.HorizonSequence, int32(84959))
assert.Equal(t, root.NetworkPassphrase, "Test SDF Network ; September 2015")
}
// failure response
hmock.On(
"GET",
"https://localhost/",
).ReturnString(404, notFoundResponse)
_, err = client.Root()
if assert.Error(t, err) {
assert.Contains(t, err.Error(), "horizon error")
horizonError, ok := err.(*Error)
assert.Equal(t, ok, true)
assert.Equal(t, horizonError.Problem.Title, "Resource Missing")
}
// connection error
hmock.On(
"GET",
"https://localhost/",
).ReturnError("http.Client error")
_, err = client.Root()
if assert.Error(t, err) {
assert.Contains(t, err.Error(), "http.Client error")
_, ok := err.(*Error)
assert.Equal(t, ok, false)
}
}
var rootResponse = `{
"_links": {
"account": {
"href": "https://horizon-testnet.stellar.org/accounts/{account_id}",
"templated": true
},
"account_transactions": {
"href": "https://horizon-testnet.stellar.org/accounts/{account_id}/transactions{?cursor,limit,order}",
"templated": true
},
"assets": {
"href": "https://horizon-testnet.stellar.org/assets{?asset_code,asset_issuer,cursor,limit,order}",
"templated": true
},
"friendbot": {
"href": "https://friendbot.stellar.org/{?addr}",
"templated": true
},
"metrics": {
"href": "https://horizon-testnet.stellar.org/metrics"
},
"order_book": {
"href": "https://horizon-testnet.stellar.org/order_book{?selling_asset_type,selling_asset_code,selling_asset_issuer,buying_asset_type,buying_asset_code,buying_asset_issuer,limit}",
"templated": true
},
"self": {
"href": "https://horizon-testnet.stellar.org/"
},
"transaction": {
"href": "https://horizon-testnet.stellar.org/transactions/{hash}",
"templated": true
},
"transactions": {
"href": "https://horizon-testnet.stellar.org/transactions{?cursor,limit,order}",
"templated": true
}
},
"horizon_version": "0.17.6-unstable-bc999a67d0b2413d8abd76153a56733c7d517484",
"core_version": "stellar-core 11.0.0 (236f831521b6724c0ae63906416faa997ef27e19)",
"history_latest_ledger": 84959,
"history_elder_ledger": 1,
"core_latest_ledger": 84959,
"network_passphrase": "Test SDF Network ; September 2015",
"current_protocol_version": 10,
"core_supported_protocol_version": 11
}`