mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-03 15:10:49 +00:00
* Websockets: Move Subscription to its own package This allows the small type to be imported from both `config` and from `stream` without an import cycle, so we don't have to repeat ourselves * Subs: Renamed Currency to Pair This was being mis-used through much of the code, and since we're already touching everything, we might as well fix it * Websockets: Add Subscription configuration * Binance: Add subscription configuration * Kucoin: Subscription configuration * Simplify GenerateDefaultSubs * Improve TestGenSubs coverage * Test Candle Sub generation * Support Candle intervals * Full responsibility for formatting Channel name on GenerateDefaultSubs OR consumer of Subscribe * Simplify generatePayloads as a result * Fix test coverage of asset types in processMarketSnapshot * Exchanges: Abstract ParallelChanOp * Tests: Generic ws mock instances * Kucoin: Fix intermittent conflict in test currs Use isolated test instance for `TestGetOpenInterest`. `TestGetOpenInterest` would occassionally change pairs before GenerateDefault Subs.
77 lines
1.9 KiB
Go
77 lines
1.9 KiB
Go
package currency
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestCurrenciesUnmarshalJSON(t *testing.T) {
|
|
var unmarshalHere Currencies
|
|
expected := "btc,usd,ltc,bro,things"
|
|
encoded, err := json.Marshal(expected)
|
|
if err != nil {
|
|
t.Fatal("Currencies UnmarshalJSON() error", err)
|
|
}
|
|
|
|
err = json.Unmarshal(encoded, &unmarshalHere)
|
|
if err != nil {
|
|
t.Fatal("Currencies UnmarshalJSON() error", err)
|
|
}
|
|
|
|
err = json.Unmarshal(encoded, &unmarshalHere)
|
|
if err != nil {
|
|
t.Fatal("Currencies UnmarshalJSON() error", err)
|
|
}
|
|
|
|
if unmarshalHere.Join() != expected {
|
|
t.Errorf("Currencies UnmarshalJSON() error expected %s but received %s",
|
|
expected, unmarshalHere.Join())
|
|
}
|
|
}
|
|
|
|
func TestCurrenciesMarshalJSON(t *testing.T) {
|
|
quickStruct := struct {
|
|
C Currencies `json:"amazingCurrencies"`
|
|
}{
|
|
C: NewCurrenciesFromStringArray([]string{"btc", "usd", "ltc", "bro", "things"}),
|
|
}
|
|
|
|
encoded, err := json.Marshal(quickStruct)
|
|
if err != nil {
|
|
t.Fatal("Currencies MarshalJSON() error", err)
|
|
}
|
|
|
|
expected := `{"amazingCurrencies":"btc,usd,ltc,bro,things"}`
|
|
if string(encoded) != expected {
|
|
t.Errorf("Currencies MarshalJSON() error expected %s but received %s",
|
|
expected, string(encoded))
|
|
}
|
|
}
|
|
|
|
func TestMatch(t *testing.T) {
|
|
matchString := []string{"btc", "usd", "ltc", "bro", "things"}
|
|
c := NewCurrenciesFromStringArray(matchString)
|
|
|
|
if !c.Match(NewCurrenciesFromStringArray(matchString)) {
|
|
t.Fatal("should match")
|
|
}
|
|
if c.Match(NewCurrenciesFromStringArray([]string{"btc", "usd", "ltc", "bro"})) {
|
|
t.Fatal("should not match")
|
|
}
|
|
if c.Match(NewCurrenciesFromStringArray([]string{"btc", "usd", "ltc", "bro", "garbo"})) {
|
|
t.Fatal("should not match")
|
|
}
|
|
}
|
|
|
|
func TestCurrenciesAdd(t *testing.T) {
|
|
c := Currencies{}
|
|
c = c.Add(BTC)
|
|
assert.Len(t, c, 1, "Should have one currency")
|
|
c = c.Add(ETH)
|
|
assert.Len(t, c, 2, "Should have two currencies")
|
|
c = c.Add(BTC)
|
|
assert.Len(t, c, 2, "Adding a duplicate should not change anything")
|
|
}
|