forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
client_test.go
60 lines (47 loc) · 1.5 KB
/
client_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
package horizonclient
import (
"github.com/stretchr/testify/assert"
"testing"
)
func setupClient() *Client {
return &Client{
HorizonURL: "https://localhost/",
AppName: "client_test",
AppVersion: "4.5.7",
}
}
func TestSetClientAppHeaders_DefaultLogic(t *testing.T) {
client := setupClient()
request := LedgerRequest{
Order: OrderAsc,
Limit: 5,
}
req, err := request.HTTPRequest(client.HorizonURL)
assert.NoError(t, err)
assert.Equal(t, 0, len(req.Header))
client.setClientAppHeaders(req)
assert.Equal(t, 4, len(req.Header))
assert.Equal(t, "go-stellar-sdk", req.Header.Get("X-Client-Name"))
assert.Equal(t, version, req.Header.Get("X-Client-Version"))
assert.Equal(t, "client_test", req.Header.Get("X-App-Name"))
assert.Equal(t, "4.5.7", req.Header.Get("X-App-Version"))
}
func TestSetClientAppHeaders_CustomHeadersLogic(t *testing.T) {
client := setupClient()
client.Headers = make(map[string]string)
client.Headers["X-Api-Key"] = "abcde"
request := LedgerRequest{
Order: OrderAsc,
Limit: 5,
}
req, err := request.HTTPRequest(client.HorizonURL)
assert.NoError(t, err)
assert.Equal(t, 0, len(req.Header))
client.setClientAppHeaders(req)
assert.Equal(t, 5, len(req.Header))
assert.Equal(t, "go-stellar-sdk", req.Header.Get("X-Client-Name"))
assert.Equal(t, version, req.Header.Get("X-Client-Version"))
assert.Equal(t, "client_test", req.Header.Get("X-App-Name"))
assert.Equal(t, "4.5.7", req.Header.Get("X-App-Version"))
assert.Equal(t, "abcde", req.Header.Get("X-Api-Key"))
}