fix(proxy): align miner success wire format
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
2b8bba790c
commit
5ba21cb9bf
3 changed files with 54 additions and 2 deletions
|
|
@ -54,6 +54,7 @@ func TestMiner_HandleLogin_Good(t *testing.T) {
|
||||||
<-done
|
<-done
|
||||||
|
|
||||||
var payload struct {
|
var payload struct {
|
||||||
|
Error json.RawMessage `json:"error"`
|
||||||
Result struct {
|
Result struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
|
|
@ -65,6 +66,9 @@ func TestMiner_HandleLogin_Good(t *testing.T) {
|
||||||
t.Fatalf("unmarshal login response: %v", err)
|
t.Fatalf("unmarshal login response: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if string(payload.Error) != "null" {
|
||||||
|
t.Fatalf("expected login response error to be null, got %s", string(payload.Error))
|
||||||
|
}
|
||||||
if payload.Result.Status != "OK" {
|
if payload.Result.Status != "OK" {
|
||||||
t.Fatalf("expected login success, got %q", payload.Result.Status)
|
t.Fatalf("expected login success, got %q", payload.Result.Status)
|
||||||
}
|
}
|
||||||
|
|
@ -293,8 +297,11 @@ func TestMiner_HandleKeepalived_Good(t *testing.T) {
|
||||||
if err := json.Unmarshal(line, &payload); err != nil {
|
if err := json.Unmarshal(line, &payload); err != nil {
|
||||||
t.Fatalf("unmarshal keepalived response: %v", err)
|
t.Fatalf("unmarshal keepalived response: %v", err)
|
||||||
}
|
}
|
||||||
if _, ok := payload["error"]; ok {
|
if _, ok := payload["error"]; !ok {
|
||||||
t.Fatalf("expected keepalived response to omit error field, got %s", string(line))
|
t.Fatalf("expected keepalived response to include error field, got %s", string(line))
|
||||||
|
}
|
||||||
|
if string(payload["error"]) != "null" {
|
||||||
|
t.Fatalf("expected keepalived response error to be null, got %s", string(payload["error"]))
|
||||||
}
|
}
|
||||||
var result struct {
|
var result struct {
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
|
|
|
||||||
43
miner_wire_test.go
Normal file
43
miner_wire_test.go
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
package proxy
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"encoding/json"
|
||||||
|
"net"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMiner_Success_WritesNullError_Good(t *testing.T) {
|
||||||
|
minerConn, clientConn := net.Pipe()
|
||||||
|
defer minerConn.Close()
|
||||||
|
defer clientConn.Close()
|
||||||
|
|
||||||
|
miner := NewMiner(minerConn, 3333, nil)
|
||||||
|
done := make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
miner.Success(7, "OK")
|
||||||
|
close(done)
|
||||||
|
}()
|
||||||
|
|
||||||
|
line, err := bufio.NewReader(clientConn).ReadBytes('\n')
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("read success response: %v", err)
|
||||||
|
}
|
||||||
|
<-done
|
||||||
|
|
||||||
|
var payload struct {
|
||||||
|
Error json.RawMessage `json:"error"`
|
||||||
|
Result struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
} `json:"result"`
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(line, &payload); err != nil {
|
||||||
|
t.Fatalf("unmarshal success response: %v", err)
|
||||||
|
}
|
||||||
|
if string(payload.Error) != "null" {
|
||||||
|
t.Fatalf("expected success response error to be null, got %s", string(payload.Error))
|
||||||
|
}
|
||||||
|
if payload.Result.Status != "OK" {
|
||||||
|
t.Fatalf("expected success status OK, got %q", payload.Result.Status)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1086,6 +1086,7 @@ func (m *Miner) replyLoginSuccess(id int64) {
|
||||||
payload := map[string]any{
|
payload := map[string]any{
|
||||||
"id": id,
|
"id": id,
|
||||||
"jsonrpc": "2.0",
|
"jsonrpc": "2.0",
|
||||||
|
"error": nil,
|
||||||
"result": result,
|
"result": result,
|
||||||
}
|
}
|
||||||
_ = m.writeJSON(payload)
|
_ = m.writeJSON(payload)
|
||||||
|
|
@ -1133,6 +1134,7 @@ func (m *Miner) Success(id int64, status string) {
|
||||||
payload := map[string]any{
|
payload := map[string]any{
|
||||||
"id": id,
|
"id": id,
|
||||||
"jsonrpc": "2.0",
|
"jsonrpc": "2.0",
|
||||||
|
"error": nil,
|
||||||
"result": map[string]any{
|
"result": map[string]any{
|
||||||
"status": status,
|
"status": status,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue