mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-09 07:26:48 +00:00
* Bump CI versions * Specifically set go version as 1.17.x bumps it to 1.18 * Another * Adjust AppVeyor * Part 1 of linter issues * Part 2 * Fix various linters and improvements * Part 3 * Finishing touches * Tests and EqualFold * Fix nitterinos plus bonus requester jobs bump for exchanges with large number of tests * Fix nitterinos and bump golangci-lint timeout for AppVeyor * Address nits, ensure all books are returned on err due to syncer regression * Fix the wiggins * Fix duplication * Fix nitterinos
111 lines
2.4 KiB
Go
111 lines
2.4 KiB
Go
package exchangeratehost
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/thrasher-corp/gocryptotrader/currency/forexprovider/base"
|
|
)
|
|
|
|
var (
|
|
e ExchangeRateHost
|
|
testCurrencies = "USD,EUR,CZK"
|
|
)
|
|
|
|
func TestMain(t *testing.M) {
|
|
err := e.Setup(base.Settings{
|
|
Name: "ExchangeRateHost",
|
|
})
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
os.Exit(t.Run())
|
|
}
|
|
|
|
func TestGetLatestRates(t *testing.T) {
|
|
_, err := e.GetLatestRates("USD", testCurrencies, 1200, 2, "")
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
}
|
|
|
|
func TestConvertCurrency(t *testing.T) {
|
|
_, err := e.ConvertCurrency("USD", "EUR", "", testCurrencies, "", time.Now(), 1200, 2)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
}
|
|
|
|
func TestGetHistoricRates(t *testing.T) {
|
|
_, err := e.GetHistoricalRates(time.Time{}, "AUD", testCurrencies, 1200, 2, "")
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
}
|
|
|
|
func TestGetTimeSeriesRates(t *testing.T) {
|
|
_, err := e.GetTimeSeries(time.Time{}, time.Now(), "USD", testCurrencies, 1200, 2, "")
|
|
if err == nil {
|
|
t.Error("empty start time show throw an error")
|
|
}
|
|
tmNow := time.Now()
|
|
_, err = e.GetTimeSeries(tmNow, tmNow, "USD", testCurrencies, 1200, 2, "")
|
|
if err == nil {
|
|
t.Error("equal times show throw an error")
|
|
}
|
|
tmStart := tmNow.AddDate(0, -3, 0)
|
|
_, err = e.GetTimeSeries(tmStart, tmNow, "USD", testCurrencies, 1200, 2, "")
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
}
|
|
|
|
func TestGetFluctuationData(t *testing.T) {
|
|
_, err := e.GetFluctuations(time.Time{}, time.Now(), "USD", testCurrencies, 1200, 2, "")
|
|
if err == nil {
|
|
t.Error("empty start time show throw an error")
|
|
}
|
|
tmNow := time.Now()
|
|
_, err = e.GetFluctuations(tmNow, tmNow, "USD", testCurrencies, 1200, 2, "")
|
|
if err == nil {
|
|
t.Error("equal times show throw an error")
|
|
}
|
|
tmStart := tmNow.AddDate(0, -3, 0)
|
|
_, err = e.GetFluctuations(tmStart, tmNow, "USD", testCurrencies, 1200, 2, "")
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
}
|
|
|
|
func TestGetSupportedSymbols(t *testing.T) {
|
|
r, err := e.GetSupportedSymbols()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, ok := r.Symbols["AUD"]; !ok {
|
|
t.Error("should contain AUD")
|
|
}
|
|
}
|
|
|
|
func TestGetGetSupportedCurrencies(t *testing.T) {
|
|
s, err := e.GetSupportedCurrencies()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(s) == 0 {
|
|
t.Error("supported currencies should be greater than 0")
|
|
}
|
|
}
|
|
|
|
func TestGetRates(t *testing.T) {
|
|
r, err := e.GetRates("USD", "")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if rate := r["USDAUD"]; rate == 0 {
|
|
t.Error("rate of USDAUD should be set")
|
|
}
|
|
}
|