From 9e87351681e7ad4e4c25862f9f35596029b702bd Mon Sep 17 00:00:00 2001 From: matst80 Date: Wed, 13 Nov 2024 22:14:04 +0100 Subject: [PATCH] update statuscode --- tcp-connection.go | 4 ++-- tcp-connection_test.go | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tcp-connection.go b/tcp-connection.go index 2a2544a..0a9f501 100644 --- a/tcp-connection.go +++ b/tcp-connection.go @@ -44,9 +44,9 @@ func MakeFrameWithPayload(msg FrameType, statusCode StatusCode, payload []byte) return FrameWithPayload{ Frame: Frame{ Type: msg, - StatusCode: 0, + StatusCode: statusCode, Length: len, - Checksum: MakeChecksum(msg, 0, len), + Checksum: MakeChecksum(msg, statusCode, len), }, Payload: payload, } diff --git a/tcp-connection_test.go b/tcp-connection_test.go index e7714eb..6f30d08 100644 --- a/tcp-connection_test.go +++ b/tcp-connection_test.go @@ -9,8 +9,11 @@ func TestGenericConnection(t *testing.T) { t.Errorf("Error listening: %v\n", err) } datta := []byte("Hello, world!") + listener.AddHandler(Ping, func(input *FrameWithPayload, resultChan chan<- FrameWithPayload) error { + resultChan <- MakeFrameWithPayload(Pong, 200, nil) + return nil + }) listener.AddHandler(1, func(input *FrameWithPayload, resultChan chan<- FrameWithPayload) error { - resultChan <- MakeFrameWithPayload(2, 200, datta) return nil }) @@ -21,6 +24,10 @@ func TestGenericConnection(t *testing.T) { if r.Type != 2 { t.Errorf("Expected type 2, got %d\n", r.Type) } + response, err := conn.Call(Ping, nil) + if err != nil || response.StatusCode != 200 || response.Type != Pong { + t.Errorf("Error connecting to remote %v\n", response) + } i := 100 results := make(chan FrameWithPayload, i) for i > 0 {