]> git.r.bdr.sh - rbdr/mobius/blobdiff - hotline/tracker_test.go
Refactor TrackerRegistration Read to io.Reader interface
[rbdr/mobius] / hotline / tracker_test.go
index 3e0be5def4a3c3f6602dc1d2925f63710eb720cc..b5c5c557226d002b6706929fc669a2b057673d2c 100644 (file)
@@ -3,6 +3,7 @@ package hotline
 import (
        "fmt"
        "github.com/stretchr/testify/assert"
+       "io"
        "reflect"
        "testing"
 )
@@ -11,7 +12,7 @@ func TestTrackerRegistration_Payload(t *testing.T) {
        type fields struct {
                Port        [2]byte
                UserCount   int
-               PassID      []byte
+               PassID      [4]byte
                Name        string
                Description string
        }
@@ -25,7 +26,7 @@ func TestTrackerRegistration_Payload(t *testing.T) {
                        fields: fields{
                                Port:        [2]byte{0x00, 0x10},
                                UserCount:   2,
-                               PassID:      []byte{0x00, 0x00, 0x00, 0x01},
+                               PassID:      [4]byte{0x00, 0x00, 0x00, 0x01},
                                Name:        "Test Serv",
                                Description: "Fooz",
                        },
@@ -51,7 +52,8 @@ func TestTrackerRegistration_Payload(t *testing.T) {
                                Name:        tt.fields.Name,
                                Description: tt.fields.Description,
                        }
-                       if got := tr.Read(); !reflect.DeepEqual(got, tt.want) {
+
+                       if got, _ := io.ReadAll(tr); !reflect.DeepEqual(got, tt.want) {
                                t.Errorf("Read() = %v, want %v", got, tt.want)
                        }
                })
@@ -139,6 +141,44 @@ func Test_serverScanner(t *testing.T) {
                        wantToken:   []byte(nil),
                        wantErr:     assert.NoError,
                },
+               {
+                       name: "when nameLen exceeds provided data",
+                       args: args{
+                               data: []byte{
+                                       0x18, 0x05, 0x30, 0x63, // IP Addr
+                                       0x15, 0x7c, // Port
+                                       0x00, 0x02, // UserCount
+                                       0x00, 0x00, // ??
+                                       0xff,             // Name Len
+                                       0x54, 0x68, 0x65, // Name
+                                       0x03,             // Desc Len
+                                       0x54, 0x54, 0x54, // Description
+                               },
+                               atEOF: false,
+                       },
+                       wantAdvance: 0,
+                       wantToken:   []byte(nil),
+                       wantErr:     assert.NoError,
+               },
+               {
+                       name: "when description len exceeds provided data",
+                       args: args{
+                               data: []byte{
+                                       0x18, 0x05, 0x30, 0x63, // IP Addr
+                                       0x15, 0x7c, // Port
+                                       0x00, 0x02, // UserCount
+                                       0x00, 0x00, // ??
+                                       0x03,             // Name Len
+                                       0x54, 0x68, 0x65, // Name
+                                       0xff,             // Desc Len
+                                       0x54, 0x54, 0x54, // Description
+                               },
+                               atEOF: false,
+                       },
+                       wantAdvance: 0,
+                       wantToken:   []byte(nil),
+                       wantErr:     assert.NoError,
+               },
        }
        for _, tt := range tests {
                t.Run(tt.name, func(t *testing.T) {