mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-03 15:10:49 +00:00
* drop common uuid v4 func and imported package as needed * removed common functions regarding json marshal and unmarshal and used the json package directly. WRT unmarshal it was calling reflect and converted to string which is also checked in the JSON package so it was doing a double up, this will be a tiny gain as it was directly used in the requester package for all our outbound requests. * add in string * explicitly throw away return error value * atleast return the error that websocket initialise returns * return error when not connected * fix comment * Adds comments * move package declarations * drop append whenever we call supported * remove unused import * Change incorrect spelling * fix tests * fix go import issue
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package currency
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
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))
|
|
}
|
|
}
|