-
Notifications
You must be signed in to change notification settings - Fork 0
/
etag_cache_test.go
49 lines (42 loc) · 1.19 KB
/
etag_cache_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
package etagcache
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"testing"
"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/assert"
)
func TestHandleEtagCache(t *testing.T) {
// Create http mock
httpmock.Activate()
defer httpmock.DeactivateAndReset()
orders, err := ioutil.ReadFile("orderbook.json")
if err != nil {
t.Errorf("Error while fetching order json response. %v", err)
}
httpmock.RegisterResponder("GET", "https://api.kite.trade/orders",
httpmock.NewStringResponder(200, string(orders)))
// Create new cache instance
cacheClient := New(ClientParam{DirPath: ""})
url := "https://api.kite.trade/orders"
req, _ := http.NewRequest("GET", url, nil)
// HTTP request params
reqParam := RequestParam{
ReqClient: req,
Headers: map[string]string{
"User-Agent": "gokiteconnect/4.0.2",
"x-kite-version": "3",
"authorization": "token api_key:access_token",
},
}
// Store and fetch response/cache data
response, err := cacheClient.HandleEtagCache(reqParam, url)
if err != nil {
fmt.Printf("Error: %v", err)
}
var js map[string]interface{}
json.Unmarshal([]byte(response), &js)
assert.Equal(t, js["status"], "success", "Orderbook request failed.")
}