aboutsummaryrefslogtreecommitdiff
path: root/hotline/util_test.go
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2023-01-18 13:52:52 -0800
committerJeff Halter <868228+jhalter@users.noreply.github.com>2023-01-18 13:52:52 -0800
commit3326539367dfa85cb2b0455d5b1c67eaaf59cf8e (patch)
treea1ebb95925e3834371e1aeb82002ce033441284f /hotline/util_test.go
parentfd5eb3ab478559a722976c8093a4c2c281019c45 (diff)
Fix threaded news bugs
1. Fix handling of article IDs sent as 4 bytes instead of 2 2. Fix incorrect article count listing that strangely only affects third party clients
Diffstat (limited to 'hotline/util_test.go')
-rw-r--r--hotline/util_test.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/hotline/util_test.go b/hotline/util_test.go
new file mode 100644
index 0000000..30ae2b6
--- /dev/null
+++ b/hotline/util_test.go
@@ -0,0 +1,47 @@
+package hotline
+
+import (
+ "fmt"
+ "github.com/stretchr/testify/assert"
+ "testing"
+)
+
+func Test_byteToInt(t *testing.T) {
+ type args struct {
+ bytes []byte
+ }
+ tests := []struct {
+ name string
+ args args
+ want int
+ wantErr assert.ErrorAssertionFunc
+ }{
+ {
+ name: "with 2 bytes of input",
+ args: args{bytes: []byte{0, 1}},
+ want: 1,
+ wantErr: assert.NoError,
+ },
+ {
+ name: "with 4 bytes of input",
+ args: args{bytes: []byte{0, 1, 0, 0}},
+ want: 65536,
+ wantErr: assert.NoError,
+ },
+ {
+ name: "with invalid number of bytes of input",
+ args: args{bytes: []byte{1, 0, 0, 0, 0, 0, 0, 0}},
+ want: 0,
+ wantErr: assert.Error,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got, err := byteToInt(tt.args.bytes)
+ if !tt.wantErr(t, err, fmt.Sprintf("byteToInt(%v)", tt.args.bytes)) {
+ return
+ }
+ assert.Equalf(t, tt.want, got, "byteToInt(%v)", tt.args.bytes)
+ })
+ }
+}