Files
gocryptotrader/exchanges/mock/common_test.go
Ryan O'Hara-Reid e99adca86f encoding/json: Add custom JSON package with build tag support for Sonic (#1623)
* tag optional sonic and allow full library conversion

* Add workflow and disallow arm and darwin usage

* Add basic hotswap benchmark

* linter: fix

* use bash

* linter: fix?

* Fix whoopsie, add to make file, also add mention in features list.

* test enforcement

* actually read documentation see if this works

* linter: fix

* linter: fix

* sonic: bump tagged version

* encoding/json: drop build tag arch and os filters

* encoding/json: consolidate tests

* encoding/json: log build tag usage

* rm superfluous builds

* glorious/nits: add template change and regen docs

* glorious/nits: update commentary on nolint directive

* glorious/nits: rm init func and log results in main.go

* Test to actually pull flag in

* linter: fix

* thrasher: nits

* gk: nits 4 goflags goooooooooo!

* gk: nits rn

* make sonic default json implementation

* screen 386

* linter: fix

* Add commentary

* glorious: nits Makefile not working

* gk: nits

* gk: nits whoops

* whoopsirino

* mention 32bit systems won't be sonic

* gk: super-duper nit of extremes

---------

Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
2025-02-20 16:05:55 +11:00

142 lines
3.1 KiB
Go

package mock
import (
"net/url"
"testing"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
)
func TestMatchURLVals(t *testing.T) {
testVal, testVal2, testVal3, emptyVal := url.Values{}, url.Values{}, url.Values{}, url.Values{}
testVal.Add("test", "test")
testVal2.Add("test2", "test2")
testVal3.Add("test", "diferentValString")
nonceVal1, nonceVal2 := url.Values{}, url.Values{}
nonceVal1.Add("nonce", "012349723587")
nonceVal2.Add("nonce", "9327373874")
var expected = false
received := MatchURLVals(testVal, emptyVal)
if received != expected {
t.Errorf("MatchURLVals error expected %v received %v",
expected,
received)
}
received = MatchURLVals(emptyVal, testVal)
if received != expected {
t.Errorf("MatchURLVals error expected %v received %v",
expected,
received)
}
received = MatchURLVals(testVal, testVal2)
if received != expected {
t.Errorf("MatchURLVals error expected %v received %v",
expected,
received)
}
received = MatchURLVals(testVal2, testVal)
if received != expected {
t.Errorf("MatchURLVals error expected %v received %v",
expected,
received)
}
received = MatchURLVals(testVal, testVal3)
if received != expected {
t.Errorf("MatchURLVals error expected %v received %v",
expected,
received)
}
received = MatchURLVals(nonceVal1, testVal2)
if received != expected {
t.Errorf("MatchURLVals error expected %v received %v",
expected,
received)
}
expected = true
received = MatchURLVals(emptyVal, emptyVal)
if received != expected {
t.Errorf("MatchURLVals error expected %v received %v",
expected,
received)
}
received = MatchURLVals(testVal, testVal)
if received != expected {
t.Errorf("MatchURLVals error expected %v received %v",
expected,
received)
}
received = MatchURLVals(nonceVal1, nonceVal2)
if received != expected {
t.Errorf("MatchURLVals error expected %v received %v",
expected,
received)
}
}
func TestDeriveURLValsFromJSON(t *testing.T) {
test1 := struct {
Things []string `json:"things"`
Data struct {
Numbers []int `json:"numbers"`
Number float64 `json:"number"`
SomeString string `json:"somestring"`
} `json:"data"`
}{
Things: []string{"hello", "world"},
Data: struct {
Numbers []int `json:"numbers"`
Number float64 `json:"number"`
SomeString string `json:"somestring"`
}{
Numbers: []int{1, 3, 3, 7},
Number: 3.14,
SomeString: "hello, peoples",
},
}
payload, err := json.Marshal(test1)
if err != nil {
t.Error("marshal error", err)
}
_, err = DeriveURLValsFromJSONMap(payload)
if err != nil {
t.Error("DeriveURLValsFromJSON error", err)
}
test2 := map[string]string{
"val": "1",
"val2": "2",
"val3": "3",
"val4": "4",
"val5": "5",
"val6": "6",
"val7": "7",
}
payload, err = json.Marshal(test2)
if err != nil {
t.Error("marshal error", err)
}
vals, err := DeriveURLValsFromJSONMap(payload)
if err != nil {
t.Error("DeriveURLValsFromJSON error", err)
}
if vals["val"][0] != "1" {
t.Error("DeriveURLValsFromJSON unexpected value",
vals["val"][0])
}
}