mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-20 07:26:46 +00:00
ftx: fix null currency.Pair UnmarshalJSON (#1049)
* fix ftx unmarshal * add tests * fix ineffectual assignment to err * Update currency/pair_test.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
This commit is contained in:
@@ -34,6 +34,11 @@ func (p *Pair) UnmarshalJSON(d []byte) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if pair == "" {
|
||||
*p = EMPTYPAIR
|
||||
return nil
|
||||
}
|
||||
|
||||
newPair, err := NewPairFromString(pair)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -70,6 +70,22 @@ func TestPairUnmarshalJSON(t *testing.T) {
|
||||
t.Errorf("Pairs UnmarshalJSON() error expected %s but received %s",
|
||||
configPair, unmarshalHere)
|
||||
}
|
||||
|
||||
encoded, err = json.Marshal(EMPTYPAIR)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = json.Unmarshal(encoded, &unmarshalHere)
|
||||
if err != nil {
|
||||
t.Fatal("Pair UnmarshalJSON() error", err)
|
||||
}
|
||||
err = json.Unmarshal([]byte("null"), &unmarshalHere)
|
||||
if err != nil {
|
||||
t.Fatal("Pair UnmarshalJSON() error", err)
|
||||
}
|
||||
if unmarshalHere != EMPTYPAIR {
|
||||
t.Fatalf("Expected EMPTYPAIR got: %s", unmarshalHere)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPairMarshalJSON(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user