implement statuscode in packets
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 2m2s

This commit is contained in:
matst80
2024-11-11 23:24:03 +01:00
parent 9c15251f67
commit 0b290a32bf
17 changed files with 295 additions and 226 deletions

View File

@@ -1,6 +1,7 @@
package main
import (
"fmt"
"log"
"testing"
)
@@ -21,6 +22,10 @@ func TestCartTcpHelpers(t *testing.T) {
messageData = string(data)
return nil
})
server.HandleCall(666, func(id CartId, data []byte) (uint32, []byte, error) {
log.Printf("Received call: %s\n", string(data))
return 3, []byte("Hello, client!"), fmt.Errorf("Det blev fel")
})
server.HandleCall(2, func(id CartId, data []byte) (uint32, []byte, error) {
log.Printf("Received call: %s\n", string(data))
return 3, []byte("Hello, client!"), nil
@@ -34,6 +39,13 @@ func TestCartTcpHelpers(t *testing.T) {
if err != nil {
t.Errorf("Error calling: %v\n", err)
}
s, err := client.Call(666, id, 3, []byte("Hello, server!"))
if err != nil {
t.Errorf("Error calling: %v\n", err)
}
if s.StatusCode != 500 {
t.Errorf("Expected 500, got %d\n", s.StatusCode)
}
for i := 0; i < 100; i++ {
_, err = client.Call(Ping, id, Pong, nil)
if err != nil {
@@ -44,8 +56,8 @@ func TestCartTcpHelpers(t *testing.T) {
if err != nil {
t.Errorf("Error calling: %v\n", err)
}
if string(answer) != "Hello, client!" {
t.Errorf("Expected answer 'Hello, client!', got %s\n", string(answer))
if string(answer.Data) != "Hello, client!" {
t.Errorf("Expected answer 'Hello, client!', got %s\n", string(answer.Data))
}
if messageData != "Hello, world!" {
t.Errorf("Expected message 'Hello, world!', got %s\n", messageData)