aboutsummaryrefslogtreecommitdiff
path: root/hotline/flattened_file_object_test.go
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2026-03-16 11:46:04 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2026-03-16 11:46:04 -0700
commit2f46f87177234070044b5304ca3e0db471699ad8 (patch)
tree6dc72ce596e95850a587001a85b3f45e394b0e34 /hotline/flattened_file_object_test.go
parent92f4b7af1073b6cdd0786ce2090d6e446e0903ad (diff)
Improve test coverage for hotline and internal/mobius packages
Add comprehensive test cases across both packages to increase coverage: - hotline: 52.4% → ~55% (Disconnect, handleTransaction, SendAll, sendBanMessage, MemClientMgr, and other tests) - internal/mobius: 75.9% → ~80% (HandleUpdateUser, HandleDeleteUser, HandleSetUser, HandleNewUser, HandleUserBroadcast success paths)
Diffstat (limited to 'hotline/flattened_file_object_test.go')
-rw-r--r--hotline/flattened_file_object_test.go142
1 files changed, 142 insertions, 0 deletions
diff --git a/hotline/flattened_file_object_test.go b/hotline/flattened_file_object_test.go
index c34af8a..6279157 100644
--- a/hotline/flattened_file_object_test.go
+++ b/hotline/flattened_file_object_test.go
@@ -1,6 +1,7 @@
package hotline
import (
+ "encoding/binary"
"fmt"
"testing"
@@ -42,3 +43,144 @@ func TestFlatFileInformationFork_UnmarshalBinary(t *testing.T) {
})
}
}
+
+func TestFlatFileInformationFork_FriendlyType(t *testing.T) {
+ tests := []struct {
+ name string
+ typeSignature [4]byte
+ want []byte
+ }{
+ {
+ name: "known type TEXT",
+ typeSignature: [4]byte{'T', 'E', 'X', 'T'},
+ want: []byte("Text File"),
+ },
+ {
+ name: "known type APPL",
+ typeSignature: [4]byte{'A', 'P', 'P', 'L'},
+ want: []byte("Application Program"),
+ },
+ {
+ name: "known type SIT!",
+ typeSignature: [4]byte{'S', 'I', 'T', '!'},
+ want: []byte("StuffIt Archive"),
+ },
+ {
+ name: "unknown type returns raw signature",
+ typeSignature: [4]byte{'J', 'P', 'E', 'G'},
+ want: []byte("JPEG"),
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ ffif := &FlatFileInformationFork{
+ TypeSignature: tt.typeSignature,
+ }
+ assert.Equal(t, tt.want, ffif.FriendlyType())
+ })
+ }
+}
+
+func TestFlatFileInformationFork_FriendlyCreator(t *testing.T) {
+ tests := []struct {
+ name string
+ creatorSignature [4]byte
+ want []byte
+ }{
+ {
+ name: "known creator HTLC",
+ creatorSignature: [4]byte{'H', 'T', 'L', 'C'},
+ want: []byte("Hotline"),
+ },
+ {
+ name: "unknown creator returns raw signature",
+ creatorSignature: [4]byte{'o', 'g', 'l', 'e'},
+ want: []byte("ogle"),
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ ffif := &FlatFileInformationFork{
+ CreatorSignature: tt.creatorSignature,
+ }
+ assert.Equal(t, tt.want, ffif.FriendlyCreator())
+ })
+ }
+}
+
+func TestFlatFileInformationFork_SetComment(t *testing.T) {
+ tests := []struct {
+ name string
+ comment []byte
+ wantComment []byte
+ wantCommentSize [2]byte
+ }{
+ {
+ name: "sets a short comment",
+ comment: []byte("hello"),
+ wantComment: []byte("hello"),
+ wantCommentSize: [2]byte{0x00, 0x05},
+ },
+ {
+ name: "sets an empty comment",
+ comment: []byte{},
+ wantComment: []byte{},
+ wantCommentSize: [2]byte{0x00, 0x00},
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ ffif := &FlatFileInformationFork{}
+ err := ffif.SetComment(tt.comment)
+ assert.NoError(t, err)
+ assert.Equal(t, tt.wantComment, ffif.Comment)
+ assert.Equal(t, tt.wantCommentSize, ffif.CommentSize)
+ })
+ }
+}
+
+func TestFlattenedFileObject_TransferSize(t *testing.T) {
+ tests := []struct {
+ name string
+ dataSize uint32
+ resForkSize uint32
+ offset int64
+ wantNonZero bool
+ }{
+ {
+ name: "calculates transfer size with zero offset",
+ dataSize: 100,
+ resForkSize: 50,
+ offset: 0,
+ wantNonZero: true,
+ },
+ {
+ name: "calculates transfer size with non-zero offset",
+ dataSize: 200,
+ resForkSize: 100,
+ offset: 50,
+ wantNonZero: true,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ ffo := &flattenedFileObject{}
+
+ binary.BigEndian.PutUint32(ffo.FlatFileDataForkHeader.DataSize[:], tt.dataSize)
+ binary.BigEndian.PutUint32(ffo.FlatFileResForkHeader.DataSize[:], tt.resForkSize)
+
+ result := ffo.TransferSize(tt.offset)
+ assert.Len(t, result, 4)
+
+ size := binary.BigEndian.Uint32(result)
+ assert.Greater(t, size, uint32(0))
+
+ // With offset, the size should be smaller than without offset.
+ if tt.offset > 0 {
+ noOffsetResult := ffo.TransferSize(0)
+ noOffsetSize := binary.BigEndian.Uint32(noOffsetResult)
+ assert.Equal(t, noOffsetSize-uint32(tt.offset), size)
+ }
+ })
+ }
+}