github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/v1/lendbook_test.go (about) 1 package bitfinex 2 3 import ( 4 "bytes" 5 "io/ioutil" 6 "net/http" 7 "testing" 8 ) 9 10 func TestLendbookGet(t *testing.T) { 11 httpDo = func(req *http.Request) (*http.Response, error) { 12 msg := `{ 13 "bids":[{ 14 "rate":"9.1287", 15 "amount":"5000.0", 16 "period":30, 17 "timestamp":"1444257541.0", 18 "frr":"No" 19 }], 20 "asks":[{ 21 "rate":"8.3695", 22 "amount":"407.5", 23 "period":2, 24 "timestamp":"1444260343.0", 25 "frr":"No" 26 }] 27 }` 28 29 resp := http.Response{ 30 Body: ioutil.NopCloser(bytes.NewBufferString(msg)), 31 StatusCode: 200, 32 } 33 return &resp, nil 34 } 35 36 book, err := NewClient().Lendbook.Get("usd", 0, 0) 37 38 if err != nil { 39 t.Error(err) 40 } 41 42 if len(book.Bids) != 1 { 43 t.Error("Expected", 1) 44 t.Error("Actual ", len(book.Bids)) 45 } 46 47 if book.Bids[0].Period != 30 { 48 t.Error("Expected", 30) 49 t.Error("Actual ", book.Bids[0].Period) 50 } 51 } 52 53 func TestLendbookLends(t *testing.T) { 54 httpDo = func(req *http.Request) (*http.Response, error) { 55 msg := `[{ 56 "rate":"9.8998", 57 "amount_lent":"22528933.77950878", 58 "amount_used":"0.0", 59 "timestamp":1444264307 60 }]` 61 62 resp := http.Response{ 63 Body: ioutil.NopCloser(bytes.NewBufferString(msg)), 64 StatusCode: 200, 65 } 66 return &resp, nil 67 } 68 69 lends, err := NewClient().Lendbook.Lends("usd") 70 71 if err != nil { 72 t.Error(err) 73 } 74 75 if len(lends) != 1 { 76 t.Error("Expected", 1) 77 t.Error("Actual ", len(lends)) 78 } 79 }