mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
* Initial implementation of HTTP mock testing framework Convert to VCR testing server. Segregate live testing via build tags. Converted Binance to VCR server Convert Bitstamp to VCR mocking tests Added VCR mock testing for localbitcoins * Add server generation for concurrent testing * Fix linter issues * Fix linter issue * fix race - potentially * revert auto assigning of host vals * Fix requested changes * Adds mock testing for ANX Switch to using TestMain functionality Added cron job usage for travis-ci to live testing Added appveyor scheduled build check for live testing * WOOPS * silly correction * Fixes fantastic linter issues * fixed another whoopsie * WOOO! * Adds gemini mock testing with additional fixes * Add docs and sharedvalue * Added tls using httptest package * Fixed issues * added explicit mock recording reference to error * Fix requested changes * strip port from mock files as they are not needed on tls server * Change incorrect names * fix requested changes * lbank update * Fix another issue * Updated readme
72 lines
1.4 KiB
Go
72 lines
1.4 KiB
Go
package mock
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"log"
|
|
"net/url"
|
|
"reflect"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// MatchURLVals matches url.Value query strings
|
|
func MatchURLVals(v1, v2 url.Values) bool {
|
|
if len(v1) != len(v2) {
|
|
return false
|
|
}
|
|
|
|
if len(v1) == 0 && len(v2) == 0 {
|
|
return true
|
|
}
|
|
|
|
for key, val := range v1 {
|
|
if key == "nonce" || key == "signature" || key == "timestamp" || key == "tonce" || key == "key" { // delta values
|
|
if _, ok := v2[key]; !ok {
|
|
return false
|
|
}
|
|
continue
|
|
}
|
|
|
|
if val2, ok := v2[key]; ok {
|
|
if strings.Join(val2, "") == strings.Join(val, "") {
|
|
continue
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
// DeriveURLValsFromJSONMap gets url vals from a map[string]string encoded JSON body
|
|
func DeriveURLValsFromJSONMap(payload []byte) (url.Values, error) {
|
|
var vals = url.Values{}
|
|
if string(payload) == "" {
|
|
return vals, nil
|
|
}
|
|
intermediary := make(map[string]interface{})
|
|
err := json.Unmarshal(payload, &intermediary)
|
|
if err != nil {
|
|
return vals, err
|
|
}
|
|
|
|
for k, v := range intermediary {
|
|
switch val := v.(type) {
|
|
case string:
|
|
vals.Add(k, val)
|
|
case bool:
|
|
vals.Add(k, strconv.FormatBool(val))
|
|
case float64:
|
|
vals.Add(k, strconv.FormatFloat(val, 'f', -1, 64))
|
|
case map[string]interface{}, []interface{}, nil:
|
|
vals.Add(k, fmt.Sprintf("%v", val))
|
|
default:
|
|
log.Println(reflect.TypeOf(val))
|
|
return vals, errors.New("unhandled conversion type, please add as needed")
|
|
}
|
|
}
|
|
|
|
return vals, nil
|
|
}
|