aboutsummaryrefslogtreecommitdiff
path: root/hotline/tracker_test.go
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2022-06-29 17:08:10 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2022-06-29 17:08:10 -0700
commit8ff2b66d1583b38298dfa415588df89631023695 (patch)
treeaad16a70e04988b138fcc614c71e5958eb082eb2 /hotline/tracker_test.go
parent7e6b49e4d6bf07cbd0df374460c92c1d88be0599 (diff)
Refactor and backfill tests for tracker listing
Diffstat (limited to 'hotline/tracker_test.go')
-rw-r--r--hotline/tracker_test.go100
1 files changed, 98 insertions, 2 deletions
diff --git a/hotline/tracker_test.go b/hotline/tracker_test.go
index 72d84ba..3e0be5d 100644
--- a/hotline/tracker_test.go
+++ b/hotline/tracker_test.go
@@ -1,6 +1,8 @@
package hotline
import (
+ "fmt"
+ "github.com/stretchr/testify/assert"
"reflect"
"testing"
)
@@ -49,9 +51,103 @@ func TestTrackerRegistration_Payload(t *testing.T) {
Name: tt.fields.Name,
Description: tt.fields.Description,
}
- if got := tr.Payload(); !reflect.DeepEqual(got, tt.want) {
- t.Errorf("Payload() = %v, want %v", got, tt.want)
+ if got := tr.Read(); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("Read() = %v, want %v", got, tt.want)
}
})
}
}
+
+func Test_serverScanner(t *testing.T) {
+ type args struct {
+ data []byte
+ atEOF bool
+ }
+ tests := []struct {
+ name string
+ args args
+ wantAdvance int
+ wantToken []byte
+ wantErr assert.ErrorAssertionFunc
+ }{
+ {
+ name: "when a full server entry is provided",
+ 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
+ 0x03, // Desc Len
+ 0x54, 0x54, 0x54, // Description
+ },
+ atEOF: false,
+ },
+ wantAdvance: 18,
+ wantToken: []byte{
+ 0x18, 0x05, 0x30, 0x63, // IP Addr
+ 0x15, 0x7c, // Port
+ 0x00, 0x02, // UserCount
+ 0x00, 0x00, // ??
+ 0x03, // Name Len
+ 0x54, 0x68, 0x65, // Name
+ 0x03, // Desc Len
+ 0x54, 0x54, 0x54, // Description
+ },
+ wantErr: assert.NoError,
+ },
+ {
+ name: "when extra bytes are provided",
+ 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
+ 0x03, // Desc Len
+ 0x54, 0x54, 0x54, // Description
+ 0x54, 0x54, 0x54, 0x54, 0x54, 0x54, 0x54, 0x54, 0x54,
+ },
+ atEOF: false,
+ },
+ wantAdvance: 18,
+ wantToken: []byte{
+ 0x18, 0x05, 0x30, 0x63, // IP Addr
+ 0x15, 0x7c, // Port
+ 0x00, 0x02, // UserCount
+ 0x00, 0x00, // ??
+ 0x03, // Name Len
+ 0x54, 0x68, 0x65, // Name
+ 0x03, // Desc Len
+ 0x54, 0x54, 0x54, // Description
+ },
+ wantErr: assert.NoError,
+ },
+ {
+ name: "when insufficient bytes are provided",
+ args: args{
+ data: []byte{
+ 0, 0,
+ },
+ atEOF: false,
+ },
+ wantAdvance: 0,
+ wantToken: []byte(nil),
+ wantErr: assert.NoError,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ gotAdvance, gotToken, err := serverScanner(tt.args.data, tt.args.atEOF)
+ if !tt.wantErr(t, err, fmt.Sprintf("serverScanner(%v, %v)", tt.args.data, tt.args.atEOF)) {
+ return
+ }
+ assert.Equalf(t, tt.wantAdvance, gotAdvance, "serverScanner(%v, %v)", tt.args.data, tt.args.atEOF)
+ assert.Equalf(t, tt.wantToken, gotToken, "serverScanner(%v, %v)", tt.args.data, tt.args.atEOF)
+ })
+ }
+}