(Engine) Variety of engine updates (#390)

* 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
This commit is contained in:
Ryan O'Hara-Reid
2019-12-03 10:06:08 +11:00
committed by Adrian Gallagher
parent c27b8657e2
commit 0c5d75b22c
70 changed files with 393 additions and 462 deletions

View File

@@ -263,62 +263,6 @@ func TestSendHTTPGetRequest(t *testing.T) {
}
}
func TestJSONEncode(t *testing.T) {
t.Parallel()
type test struct {
Status int `json:"status"`
Data []struct {
Address string `json:"address"`
Balance float64 `json:"balance"`
Nonce interface{} `json:"nonce"`
Code string `json:"code"`
Name interface{} `json:"name"`
Storage interface{} `json:"storage"`
FirstSeen interface{} `json:"firstSeen"`
} `json:"data"`
}
expectOutputString := `{"status":0,"data":null}`
v := test{}
bitey, err := JSONEncode(v)
if err != nil {
t.Errorf("common JSONEncode error: %s", err)
}
if string(bitey) != expectOutputString {
t.Error("common JSONEncode error")
}
_, err = JSONEncode("WigWham")
if err != nil {
t.Errorf("common JSONEncode error: %s", err)
}
}
func TestJSONDecode(t *testing.T) {
t.Parallel()
var data []byte
result := "Not a memory address"
err := JSONDecode(data, result)
if err == nil {
t.Error("Common JSONDecode, unmarshalled when address not supplied")
}
type test struct {
Status int `json:"status"`
Data []struct {
Address string `json:"address"`
Balance float64 `json:"balance"`
} `json:"data"`
}
var v test
data = []byte(`{"status":1,"data":null}`)
err = JSONDecode(data, &v)
if err != nil || v.Status != 1 {
t.Errorf("Common JSONDecode. Data: %v \nError: %s",
v, err)
}
}
func TestEncodeURLValues(t *testing.T) {
t.Parallel()
urlstring := "https://www.test.com"