diff options
Diffstat (limited to 'hotline')
| -rw-r--r-- | hotline/access_test.go | 5 | ||||
| -rw-r--r-- | hotline/account.go | 3 | ||||
| -rw-r--r-- | hotline/chat.go | 3 | ||||
| -rw-r--r-- | hotline/chat_test.go | 3 | ||||
| -rw-r--r-- | hotline/client_conn.go | 3 | ||||
| -rw-r--r-- | hotline/client_conn_test.go | 1 | ||||
| -rw-r--r-- | hotline/client_manager.go | 3 | ||||
| -rw-r--r-- | hotline/config.go | 26 | ||||
| -rw-r--r-- | hotline/field_test.go | 3 | ||||
| -rw-r--r-- | hotline/file_name_with_info_test.go | 3 | ||||
| -rw-r--r-- | hotline/file_path_test.go | 3 | ||||
| -rw-r--r-- | hotline/file_store.go | 3 | ||||
| -rw-r--r-- | hotline/file_transfer_test.go | 23 | ||||
| -rw-r--r-- | hotline/files_test.go | 3 | ||||
| -rw-r--r-- | hotline/flattened_file_object.go | 2 | ||||
| -rw-r--r-- | hotline/flattened_file_object_test.go | 3 | ||||
| -rw-r--r-- | hotline/news_test.go | 61 | ||||
| -rw-r--r-- | hotline/server_blackbox_test.go | 3 | ||||
| -rw-r--r-- | hotline/server_test.go | 23 | ||||
| -rw-r--r-- | hotline/stats_test.go | 85 | ||||
| -rw-r--r-- | hotline/transaction_test.go | 3 | ||||
| -rw-r--r-- | hotline/transfer_test.go | 3 | ||||
| -rw-r--r-- | hotline/user_test.go | 3 |
23 files changed, 145 insertions, 126 deletions
diff --git a/hotline/access_test.go b/hotline/access_test.go index fa2f6f6..2c5b8f4 100644 --- a/hotline/access_test.go +++ b/hotline/access_test.go @@ -1,11 +1,12 @@ package hotline import ( + "strings" + "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "gopkg.in/yaml.v3" - "strings" - "testing" ) func Test_accessBitmap_IsSet(t *testing.T) { diff --git a/hotline/account.go b/hotline/account.go index 39ea974..37fb956 100644 --- a/hotline/account.go +++ b/hotline/account.go @@ -3,9 +3,10 @@ package hotline import ( "encoding/binary" "fmt" - "golang.org/x/crypto/bcrypt" "io" "slices" + + "golang.org/x/crypto/bcrypt" ) const GuestAccount = "guest" // default account used when no login is provided for a connection diff --git a/hotline/chat.go b/hotline/chat.go index dcde1d3..f35fac5 100644 --- a/hotline/chat.go +++ b/hotline/chat.go @@ -2,9 +2,10 @@ package hotline import ( "crypto/rand" - "github.com/stretchr/testify/mock" "slices" "sync" + + "github.com/stretchr/testify/mock" ) type PrivateChat struct { diff --git a/hotline/chat_test.go b/hotline/chat_test.go index 0bacc09..e08a81b 100644 --- a/hotline/chat_test.go +++ b/hotline/chat_test.go @@ -1,8 +1,9 @@ package hotline import ( - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestMemChatManager(t *testing.T) { diff --git a/hotline/client_conn.go b/hotline/client_conn.go index d324591..a203630 100644 --- a/hotline/client_conn.go +++ b/hotline/client_conn.go @@ -4,11 +4,12 @@ import ( "cmp" "encoding/binary" "fmt" - "golang.org/x/crypto/bcrypt" "io" "log/slog" "strings" "sync" + + "golang.org/x/crypto/bcrypt" ) var clientConnSortFunc = func(a, b *ClientConn) int { diff --git a/hotline/client_conn_test.go b/hotline/client_conn_test.go index 9f04d66..e5acf82 100644 --- a/hotline/client_conn_test.go +++ b/hotline/client_conn_test.go @@ -1,2 +1 @@ package hotline - diff --git a/hotline/client_manager.go b/hotline/client_manager.go index ab6372c..22d096d 100644 --- a/hotline/client_manager.go +++ b/hotline/client_manager.go @@ -3,10 +3,11 @@ package hotline import ( "cmp" "encoding/binary" - "github.com/stretchr/testify/mock" "slices" "sync" "sync/atomic" + + "github.com/stretchr/testify/mock" ) type ClientID [2]byte diff --git a/hotline/config.go b/hotline/config.go index 75d5c4d..d918ecb 100644 --- a/hotline/config.go +++ b/hotline/config.go @@ -1,18 +1,18 @@ package hotline type Config struct { - Name string `yaml:"Name" validate:"required,max=50"` // Name used for Tracker registration - Description string `yaml:"Description" validate:"required,max=200"` // Description used for Tracker registration + Name string `yaml:"Name" validate:"required,max=50"` // Name used for Tracker registration + Description string `yaml:"Description" validate:"required,max=200"` // Description used for Tracker registration BannerFile string `yaml:"BannerFile" validate:"omitempty,bannerext"` // Path to Banner jpg or gif - FileRoot string `yaml:"FileRoot" validate:"required"` // Path to Files - EnableTrackerRegistration bool `yaml:"EnableTrackerRegistration"` // Toggle Tracker Registration - Trackers []string `yaml:"Trackers" validate:"dive,hostname_port"` // List of trackers that the server should register with - NewsDelimiter string `yaml:"NewsDelimiter"` // String used to separate news posts - NewsDateFormat string `yaml:"NewsDateFormat"` // Go template string to customize news date format - MaxDownloads int `yaml:"MaxDownloads"` // Global simultaneous download limit - MaxDownloadsPerClient int `yaml:"MaxDownloadsPerClient"` // Per client simultaneous download limit - MaxConnectionsPerIP int `yaml:"MaxConnectionsPerIP"` // Max connections per IP - PreserveResourceForks bool `yaml:"PreserveResourceForks"` // Enable preservation of file info and resource forks in sidecar files - IgnoreFiles []string `yaml:"IgnoreFiles"` // List of regular expression for filtering files from the file list - EnableBonjour bool `yaml:"EnableBonjour"` // Enable service announcement on local network with Bonjour + FileRoot string `yaml:"FileRoot" validate:"required"` // Path to Files + EnableTrackerRegistration bool `yaml:"EnableTrackerRegistration"` // Toggle Tracker Registration + Trackers []string `yaml:"Trackers" validate:"dive,hostname_port"` // List of trackers that the server should register with + NewsDelimiter string `yaml:"NewsDelimiter"` // String used to separate news posts + NewsDateFormat string `yaml:"NewsDateFormat"` // Go template string to customize news date format + MaxDownloads int `yaml:"MaxDownloads"` // Global simultaneous download limit + MaxDownloadsPerClient int `yaml:"MaxDownloadsPerClient"` // Per client simultaneous download limit + MaxConnectionsPerIP int `yaml:"MaxConnectionsPerIP"` // Max connections per IP + PreserveResourceForks bool `yaml:"PreserveResourceForks"` // Enable preservation of file info and resource forks in sidecar files + IgnoreFiles []string `yaml:"IgnoreFiles"` // List of regular expression for filtering files from the file list + EnableBonjour bool `yaml:"EnableBonjour"` // Enable service announcement on local network with Bonjour } diff --git a/hotline/field_test.go b/hotline/field_test.go index 3440b0d..6dff102 100644 --- a/hotline/field_test.go +++ b/hotline/field_test.go @@ -2,8 +2,9 @@ package hotline import ( "fmt" - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestHello(t *testing.T) { diff --git a/hotline/file_name_with_info_test.go b/hotline/file_name_with_info_test.go index 5095acf..be9addf 100644 --- a/hotline/file_name_with_info_test.go +++ b/hotline/file_name_with_info_test.go @@ -1,9 +1,10 @@ package hotline import ( - "github.com/stretchr/testify/assert" "io" "testing" + + "github.com/stretchr/testify/assert" ) func TestFileNameWithInfo_MarshalBinary(t *testing.T) { diff --git a/hotline/file_path_test.go b/hotline/file_path_test.go index 23c9a96..ee0cbac 100644 --- a/hotline/file_path_test.go +++ b/hotline/file_path_test.go @@ -2,8 +2,9 @@ package hotline import ( "fmt" - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestFilePath_Write(t *testing.T) { diff --git a/hotline/file_store.go b/hotline/file_store.go index 1525e2e..8c18256 100644 --- a/hotline/file_store.go +++ b/hotline/file_store.go @@ -1,10 +1,11 @@ package hotline import ( - "github.com/stretchr/testify/mock" "io/fs" "os" "time" + + "github.com/stretchr/testify/mock" ) type FileStore interface { diff --git a/hotline/file_transfer_test.go b/hotline/file_transfer_test.go index ba29910..a5c4afe 100644 --- a/hotline/file_transfer_test.go +++ b/hotline/file_transfer_test.go @@ -2,9 +2,10 @@ package hotline import ( "encoding/binary" - "github.com/stretchr/testify/assert" "io" "testing" + + "github.com/stretchr/testify/assert" ) func TestFileTransfer_String(t *testing.T) { @@ -178,10 +179,10 @@ func TestFileHeader_Payload(t *testing.T) { func Test_folderUpload_FormattedPath(t *testing.T) { tests := []struct { - name string - pathItemCount [2]byte - fileNamePath []byte - want string + name string + pathItemCount [2]byte + fileNamePath []byte + want string }{ { name: "empty path", @@ -210,7 +211,7 @@ func Test_folderUpload_FormattedPath(t *testing.T) { 0x04, // segment length 0x75, 0x73, 0x65, 0x72, // "user" 0x00, 0x00, // path separator - 0x09, // segment length + 0x09, // segment length 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, // "documents" }, want: "home/user/documents", @@ -220,10 +221,10 @@ func Test_folderUpload_FormattedPath(t *testing.T) { pathItemCount: [2]byte{0x00, 0x02}, fileNamePath: []byte{ 0x00, 0x00, // path separator - 0x07, // segment length + 0x07, // segment length 0x4d, 0x79, 0x20, 0x46, 0x69, 0x6c, 0x65, // "My File" 0x00, 0x00, // path separator - 0x0d, // segment length (13 bytes) + 0x0d, // segment length (13 bytes) 0x49, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6e, 0x74, 0x2e, 0x74, 0x78, 0x74, // "Important.txt" }, want: "My File/Important.txt", @@ -239,8 +240,8 @@ func Test_folderUpload_FormattedPath(t *testing.T) { 0x01, // segment length 0x62, // "b" 0x00, 0x00, // path separator - 0x01, // segment length - 0x63, // "c" + 0x01, // segment length + 0x63, // "c" }, want: "a/b/c", }, @@ -249,7 +250,7 @@ func Test_folderUpload_FormattedPath(t *testing.T) { pathItemCount: [2]byte{0x00, 0x01}, fileNamePath: []byte{ 0x00, 0x00, // path separator - 0x08, // segment length + 0x08, // segment length 0x74, 0x65, 0x73, 0x74, 0x40, 0x24, 0x25, 0x26, // "test@$%&" }, want: "test@$%&", diff --git a/hotline/files_test.go b/hotline/files_test.go index 9bed670..3070313 100644 --- a/hotline/files_test.go +++ b/hotline/files_test.go @@ -3,10 +3,11 @@ package hotline import ( "bytes" "encoding/binary" - "github.com/stretchr/testify/assert" "os" "path/filepath" "testing" + + "github.com/stretchr/testify/assert" ) func TestEncodeFilePath(t *testing.T) { diff --git a/hotline/flattened_file_object.go b/hotline/flattened_file_object.go index 7c0cd7d..0300c71 100644 --- a/hotline/flattened_file_object.go +++ b/hotline/flattened_file_object.go @@ -45,7 +45,7 @@ type FlatFileInformationFork struct { func NewFlatFileInformationFork(fileName string, modifyTime [8]byte, typeSignature string, creatorSignature string) FlatFileInformationFork { return FlatFileInformationFork{ - Platform: PlatformAMAC, // TODO: Remove hardcode to support "MWIN" Platform (maybe?) + Platform: PlatformAMAC, // TODO: Remove hardcode to support "MWIN" Platform (maybe?) TypeSignature: [4]byte([]byte(typeSignature)), // TODO: Don't infer types from filename CreatorSignature: [4]byte([]byte(creatorSignature)), // TODO: Don't infer types from filename PlatformFlags: [4]byte{0, 0, 1, 0}, // TODO: What is this? diff --git a/hotline/flattened_file_object_test.go b/hotline/flattened_file_object_test.go index 274ca2b..c34af8a 100644 --- a/hotline/flattened_file_object_test.go +++ b/hotline/flattened_file_object_test.go @@ -2,8 +2,9 @@ package hotline import ( "fmt" - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestFlatFileInformationFork_UnmarshalBinary(t *testing.T) { diff --git a/hotline/news_test.go b/hotline/news_test.go index 2af3cd2..80676f1 100644 --- a/hotline/news_test.go +++ b/hotline/news_test.go @@ -1,9 +1,10 @@ package hotline import ( - "github.com/stretchr/testify/assert" "io" "testing" + + "github.com/stretchr/testify/assert" ) func TestNewsCategoryListData15_MarshalBinary(t *testing.T) { @@ -289,8 +290,8 @@ func TestNewsArtListData_Write(t *testing.T) { 0x00, 0x00, 0x00, 0x05, // Count: 5 0x04, // Name length: 4 0x74, 0x65, 0x73, 0x74, // Name: "test" - 0x04, // Description length: 4 - 0x64, 0x65, 0x73, 0x63, // Description: "desc" + 0x04, // Description length: 4 + 0x64, 0x65, 0x73, 0x63, // Description: "desc" }, wantID: [4]byte{0x00, 0x01, 0x02, 0x03}, wantCount: 5, @@ -307,9 +308,9 @@ func TestNewsArtListData_Write(t *testing.T) { 0x00, 0x00, 0x00, 0x01, // Count: 1 0x04, // Name length: 4 0x74, 0x65, 0x73, 0x74, // Name: "test" - 0x04, // Description length: 4 - 0x64, 0x65, 0x73, 0x63, // Description: "desc" - 0xAA, 0xBB, 0xCC, // NewsArtList data + 0x04, // Description length: 4 + 0x64, 0x65, 0x73, 0x63, // Description: "desc" + 0xAA, 0xBB, 0xCC, // NewsArtList data }, wantID: [4]byte{0x00, 0x01, 0x02, 0x03}, wantCount: 1, @@ -340,9 +341,9 @@ func TestNewsArtListData_Write(t *testing.T) { input: []byte{ 0x00, 0x00, 0x00, 0x00, // ID 0x00, 0x00, 0x00, 0x0A, // Count: 10 - 0x0A, // Name length: 10 + 0x0A, // Name length: 10 0x4C, 0x6F, 0x6E, 0x67, 0x65, 0x72, 0x4E, 0x61, 0x6D, 0x65, // Name: "LongerName" - 0x0B, // Description length: 11 + 0x0B, // Description length: 11 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6F, 0x6E, // Description: "Description" }, wantID: [4]byte{0x00, 0x00, 0x00, 0x00}, @@ -405,8 +406,8 @@ func TestNewsArtListData_Write_PartialData(t *testing.T) { { name: "split across ID boundary", chunks: [][]byte{ - {0x00, 0x01}, // First 2 bytes of ID - {0x02, 0x03}, // Last 2 bytes of ID + {0x00, 0x01}, // First 2 bytes of ID + {0x02, 0x03}, // Last 2 bytes of ID {0x00, 0x00, 0x00, 0x02}, // Count: 2 {0x03}, // Name length: 3 {0x66, 0x6f, 0x6f}, // Name: "foo" @@ -425,10 +426,10 @@ func TestNewsArtListData_Write_PartialData(t *testing.T) { chunks: [][]byte{ {0x00, 0x00, 0x00, 0x00}, // ID {0x00, 0x00, 0x00, 0x01}, // Count: 1 - {0x05}, // Name length: 5 - {0x68, 0x65}, // "he" - {0x6c, 0x6c, 0x6f}, // "llo" - {0x00}, // Description length: 0 + {0x05}, // Name length: 5 + {0x68, 0x65}, // "he" + {0x6c, 0x6c, 0x6f}, // "llo" + {0x00}, // Description length: 0 }, wantID: [4]byte{0x00, 0x00, 0x00, 0x00}, wantCount: 1, @@ -442,10 +443,10 @@ func TestNewsArtListData_Write_PartialData(t *testing.T) { chunks: [][]byte{ {0xAA, 0xBB, 0xCC, 0xDD}, // ID {0x00, 0x00, 0x00, 0x05}, // Count: 5 - {0x01, 0x41}, // Name length: 1, Name: "A" - {0x01, 0x42}, // Description length: 1, Description: "B" - {0x11, 0x22}, // Article list part 1 - {0x33, 0x44, 0x55}, // Article list part 2 + {0x01, 0x41}, // Name length: 1, Name: "A" + {0x01, 0x42}, // Description length: 1, Description: "B" + {0x11, 0x22}, // Article list part 1 + {0x33, 0x44, 0x55}, // Article list part 2 }, wantID: [4]byte{0xAA, 0xBB, 0xCC, 0xDD}, wantCount: 5, @@ -459,7 +460,7 @@ func TestNewsArtListData_Write_PartialData(t *testing.T) { chunks: [][]byte{ {0x01}, {0x02}, {0x03}, {0x04}, // ID {0x00}, {0x00}, {0x00}, {0x00}, // Count: 0 - {0x02}, // Name length: 2 + {0x02}, // Name length: 2 {0x41}, {0x42}, // Name: "AB" {0x00}, // Description length: 0 }, @@ -684,8 +685,8 @@ func TestNewsCategoryListData15_Write(t *testing.T) { input: []byte{ 0x00, 0x02, // Type: Bundle 0x00, 0x01, // Count: 1 - 0x03, // Name length: 3 - 0x66, 0x6f, 0x6f, // Name: "foo" + 0x03, // Name length: 3 + 0x66, 0x6f, 0x6f, // Name: "foo" }, wantType: [2]byte{0x00, 0x02}, wantName: "foo", @@ -727,7 +728,7 @@ func TestNewsCategoryListData15_Write(t *testing.T) { input: []byte{ 0x00, 0x02, // Type: Bundle 0x00, 0x05, // Count: 5 - 0x0a, // Name length: 10 + 0x0a, // Name length: 10 0x4c, 0x6f, 0x6e, 0x67, 0x65, 0x72, 0x4e, 0x61, 0x6d, 0x65, // Name: "LongerName" }, wantType: [2]byte{0x00, 0x02}, @@ -758,9 +759,9 @@ func TestNewsCategoryListData15_Write(t *testing.T) { func TestNewsCategoryListData15_WriteRead_RoundTrip(t *testing.T) { tests := []struct { - name string - newscat NewsCategoryListData15 - wantErr bool + name string + newscat NewsCategoryListData15 + wantErr bool }{ { name: "bundle round trip", @@ -844,11 +845,11 @@ func TestNewsCategoryListData15_Write_PartialData(t *testing.T) { { name: "split across type boundary", chunks: [][]byte{ - {0x00}, // First byte of type - {0x02}, // Second byte of type - {0x00, 0x01}, // Count - {0x03}, // Name length - {0x66, 0x6f, 0x6f}, // Name: "foo" + {0x00}, // First byte of type + {0x02}, // Second byte of type + {0x00, 0x01}, // Count + {0x03}, // Name length + {0x66, 0x6f, 0x6f}, // Name: "foo" }, wantType: [2]byte{0x00, 0x02}, wantName: "foo", diff --git a/hotline/server_blackbox_test.go b/hotline/server_blackbox_test.go index 888ca3f..7033703 100644 --- a/hotline/server_blackbox_test.go +++ b/hotline/server_blackbox_test.go @@ -4,11 +4,12 @@ import ( "cmp" "encoding/binary" "encoding/hex" - "github.com/stretchr/testify/assert" "log/slog" "os" "slices" "testing" + + "github.com/stretchr/testify/assert" ) func NewTestLogger() *slog.Logger { diff --git a/hotline/server_test.go b/hotline/server_test.go index 574aae7..db70480 100644 --- a/hotline/server_test.go +++ b/hotline/server_test.go @@ -5,13 +5,14 @@ import ( "context" "encoding/binary" "fmt" - "github.com/stretchr/testify/assert" "io" "log/slog" "os" "strings" "testing" "time" + + "github.com/stretchr/testify/assert" ) type mockReadWriter struct { @@ -400,20 +401,20 @@ func TestServer_registerWithTrackers(t *testing.T) { func TestServer_registerWithTrackers_ContextCancellation(t *testing.T) { tests := []struct { - name string - cancelAfter time.Duration - expectedCalls int // Number of expected registration calls before cancellation - trackerCount int + name string + cancelAfter time.Duration + expectedCalls int // Number of expected registration calls before cancellation + trackerCount int }{ { - name: "immediate cancellation", - cancelAfter: 10 * time.Millisecond, + name: "immediate cancellation", + cancelAfter: 10 * time.Millisecond, expectedCalls: 2, // Should complete immediate registration trackerCount: 2, }, { - name: "cancellation after first ticker", - cancelAfter: 100 * time.Millisecond, + name: "cancellation after first ticker", + cancelAfter: 100 * time.Millisecond, expectedCalls: 2, // Should only do immediate registration within 100ms trackerCount: 2, }, @@ -470,10 +471,10 @@ func TestServer_registerWithTrackers_ContextCancellation(t *testing.T) { func TestServer_registerWithTrackers_PeriodicRegistration(t *testing.T) { t.Skip("Skipping timing-sensitive test - would take 5+ minutes to run reliably") - + // This test would verify that periodic re-registration happens every trackerUpdateFrequency seconds // but it's impractical to run in normal test suites due to the 300-second interval - + mockRegistrar := &MockTrackerRegistrar{} config := Config{ EnableTrackerRegistration: true, diff --git a/hotline/stats_test.go b/hotline/stats_test.go index 2174227..d853dee 100644 --- a/hotline/stats_test.go +++ b/hotline/stats_test.go @@ -1,9 +1,10 @@ package hotline import ( - "github.com/stretchr/testify/assert" "testing" "time" + + "github.com/stretchr/testify/assert" ) func TestStats_Increment(t *testing.T) { @@ -51,13 +52,13 @@ func TestStats_Increment(t *testing.T) { func TestStats_Increment_Multiple_Calls(t *testing.T) { stats := NewStats() - + stats.Increment(StatCurrentlyConnected) assert.Equal(t, 1, stats.Get(StatCurrentlyConnected)) - + stats.Increment(StatCurrentlyConnected) assert.Equal(t, 2, stats.Get(StatCurrentlyConnected)) - + stats.Increment(StatCurrentlyConnected, StatDownloadCounter) assert.Equal(t, 3, stats.Get(StatCurrentlyConnected)) assert.Equal(t, 1, stats.Get(StatDownloadCounter)) @@ -65,28 +66,28 @@ func TestStats_Increment_Multiple_Calls(t *testing.T) { func TestStats_Decrement(t *testing.T) { tests := []struct { - name string - setupValue int - key int - expected int + name string + setupValue int + key int + expected int }{ { - name: "decrement from positive value", - setupValue: 5, - key: StatCurrentlyConnected, - expected: 4, + name: "decrement from positive value", + setupValue: 5, + key: StatCurrentlyConnected, + expected: 4, }, { - name: "decrement from zero stays zero", - setupValue: 0, - key: StatCurrentlyConnected, - expected: 0, + name: "decrement from zero stays zero", + setupValue: 0, + key: StatCurrentlyConnected, + expected: 0, }, { - name: "decrement from one", - setupValue: 1, - key: StatCurrentlyConnected, - expected: 0, + name: "decrement from one", + setupValue: 1, + key: StatCurrentlyConnected, + expected: 0, }, } @@ -94,9 +95,9 @@ func TestStats_Decrement(t *testing.T) { t.Run(tt.name, func(t *testing.T) { stats := NewStats() stats.Set(tt.key, tt.setupValue) - + stats.Decrement(tt.key) - + assert.Equal(t, tt.expected, stats.Get(tt.key)) }) } @@ -104,13 +105,13 @@ func TestStats_Decrement(t *testing.T) { func TestStats_Decrement_Multiple_Calls(t *testing.T) { stats := NewStats() - + stats.Set(StatCurrentlyConnected, 10) assert.Equal(t, 10, stats.Get(StatCurrentlyConnected)) - + stats.Decrement(StatCurrentlyConnected) assert.Equal(t, 9, stats.Get(StatCurrentlyConnected)) - + stats.Decrement(StatCurrentlyConnected) assert.Equal(t, 8, stats.Get(StatCurrentlyConnected)) } @@ -151,13 +152,13 @@ func TestStats_Set(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { stats := NewStats() - + if tt.name == "overwrite existing value" { stats.Set(tt.key, 50) } - + stats.Set(tt.key, tt.value) - + assert.Equal(t, tt.expected, stats.Get(tt.key)) }) } @@ -193,13 +194,13 @@ func TestStats_Get(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { stats := NewStats() - + if tt.name == "get after increment" { stats.Increment(tt.key) } else { stats.Set(tt.key, tt.setValue) } - + result := stats.Get(tt.key) assert.Equal(t, tt.expected, result) }) @@ -208,7 +209,7 @@ func TestStats_Get(t *testing.T) { func TestStats_Get_Default_Values(t *testing.T) { stats := NewStats() - + expectedDefaults := map[int]int{ StatCurrentlyConnected: 0, StatDownloadsInProgress: 0, @@ -219,7 +220,7 @@ func TestStats_Get_Default_Values(t *testing.T) { StatUploadCounter: 0, StatConnectionCounter: 0, } - + for key, expected := range expectedDefaults { assert.Equal(t, expected, stats.Get(key)) } @@ -227,10 +228,10 @@ func TestStats_Get_Default_Values(t *testing.T) { func TestStats_Values(t *testing.T) { stats := NewStats() - + // Test default values values := stats.Values() - + assert.Equal(t, 0, values["CurrentlyConnected"]) assert.Equal(t, 0, values["DownloadsInProgress"]) assert.Equal(t, 0, values["UploadsInProgress"]) @@ -240,7 +241,7 @@ func TestStats_Values(t *testing.T) { assert.Equal(t, 0, values["DownloadCounter"]) assert.Equal(t, 0, values["UploadCounter"]) assert.NotNil(t, values["Since"]) - + // Verify Since is a time.Time _, ok := values["Since"].(time.Time) assert.True(t, ok, "Since should be a time.Time") @@ -248,15 +249,15 @@ func TestStats_Values(t *testing.T) { func TestStats_Values_WithModifiedStats(t *testing.T) { stats := NewStats() - + // Modify some stats stats.Set(StatCurrentlyConnected, 10) stats.Set(StatDownloadsInProgress, 5) stats.Increment(StatConnectionCounter) stats.Increment(StatDownloadCounter, StatUploadCounter) - + values := stats.Values() - + assert.Equal(t, 10, values["CurrentlyConnected"]) assert.Equal(t, 5, values["DownloadsInProgress"]) assert.Equal(t, 0, values["UploadsInProgress"]) @@ -270,7 +271,7 @@ func TestStats_Values_WithModifiedStats(t *testing.T) { func TestStats_Values_ContainsAllKeys(t *testing.T) { stats := NewStats() values := stats.Values() - + expectedKeys := []string{ "CurrentlyConnected", "DownloadsInProgress", @@ -282,12 +283,12 @@ func TestStats_Values_ContainsAllKeys(t *testing.T) { "UploadCounter", "Since", } - + for _, key := range expectedKeys { _, exists := values[key] assert.True(t, exists, "Key %s should exist in Values() output", key) } - + // Should have exactly 9 keys assert.Equal(t, 9, len(values)) -}
\ No newline at end of file +} diff --git a/hotline/transaction_test.go b/hotline/transaction_test.go index 97d865d..44afa6c 100644 --- a/hotline/transaction_test.go +++ b/hotline/transaction_test.go @@ -2,8 +2,9 @@ package hotline import ( "fmt" - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func Test_transactionScanner(t *testing.T) { diff --git a/hotline/transfer_test.go b/hotline/transfer_test.go index 9155ad7..94a14b6 100644 --- a/hotline/transfer_test.go +++ b/hotline/transfer_test.go @@ -3,9 +3,10 @@ package hotline import ( "bytes" "fmt" - "github.com/stretchr/testify/assert" "io" "testing" + + "github.com/stretchr/testify/assert" ) func TestTransfer_Write(t *testing.T) { diff --git a/hotline/user_test.go b/hotline/user_test.go index 2429009..22def00 100644 --- a/hotline/user_test.go +++ b/hotline/user_test.go @@ -2,8 +2,9 @@ package hotline import ( "bytes" - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestReadUser(t *testing.T) { |