From 14cf5207784ba575002e7d888dcf73ac4b97f0b7 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 2 Apr 2026 18:20:32 +0100 Subject: [PATCH] ax(batch): apply Good/Bad/Ugly test naming convention across all packages Renames test functions to follow TestFilename_Function_{Good,Bad,Ugly} convention per AX test naming rules. Covers profile_manager_test.go (11 tests), events_test.go (9 tests), container_test.go (8 tests), logger_test.go (9 tests), database_test.go (10 tests). Co-Authored-By: Charon --- pkg/database/database_test.go | 22 +++++++++++----------- pkg/logging/logger_test.go | 18 +++++++++--------- pkg/mining/container_test.go | 20 ++++++++++---------- pkg/mining/events_test.go | 18 +++++++++--------- pkg/mining/profile_manager_test.go | 22 +++++++++++----------- 5 files changed, 50 insertions(+), 50 deletions(-) diff --git a/pkg/database/database_test.go b/pkg/database/database_test.go index fa2bc1f..6b09438 100644 --- a/pkg/database/database_test.go +++ b/pkg/database/database_test.go @@ -51,7 +51,7 @@ func TestDatabase_Initialize_Bad(t *testing.T) { } } -func TestClose(t *testing.T) { +func TestDatabase_Close_Good(t *testing.T) { cleanup := setupTestDB(t) defer cleanup() @@ -61,7 +61,7 @@ func TestClose(t *testing.T) { } } -func TestHashrateStorage(t *testing.T) { +func TestDatabase_HashrateStorage_Good(t *testing.T) { cleanup := setupTestDB(t) defer cleanup() @@ -93,7 +93,7 @@ func TestHashrateStorage(t *testing.T) { } } -func TestGetHashrateStats(t *testing.T) { +func TestDatabase_GetHashrateStats_Good(t *testing.T) { cleanup := setupTestDB(t) defer cleanup() @@ -137,7 +137,7 @@ func TestGetHashrateStats(t *testing.T) { } } -func TestDefaultConfig(t *testing.T) { +func TestDatabase_DefaultConfig_Good(t *testing.T) { config := defaultConfig() if !config.Enabled { @@ -149,7 +149,7 @@ func TestDefaultConfig(t *testing.T) { } } -func TestCleanupRetention(t *testing.T) { +func TestDatabase_CleanupRetention_Good(t *testing.T) { cleanup := setupTestDB(t) defer cleanup() @@ -216,7 +216,7 @@ func TestCleanupRetention(t *testing.T) { } } -func TestGetHashrateHistoryTimeRange(t *testing.T) { +func TestDatabase_GetHashrateHistoryTimeRange_Good(t *testing.T) { cleanup := setupTestDB(t) defer cleanup() @@ -269,7 +269,7 @@ func TestGetHashrateHistoryTimeRange(t *testing.T) { } } -func TestMultipleMinerStats(t *testing.T) { +func TestDatabase_MultipleMinerStats_Good(t *testing.T) { cleanup := setupTestDB(t) defer cleanup() @@ -332,7 +332,7 @@ func TestMultipleMinerStats(t *testing.T) { } } -func TestIsInitialized(t *testing.T) { +func TestDatabase_IsInitialized_Good(t *testing.T) { // Before initialization Close() // Ensure clean state if isInitialized() { @@ -354,7 +354,7 @@ func TestIsInitialized(t *testing.T) { } } -func TestSchemaCreation(t *testing.T) { +func TestDatabase_SchemaCreation_Good(t *testing.T) { cleanup := setupTestDB(t) defer cleanup() @@ -388,7 +388,7 @@ func TestSchemaCreation(t *testing.T) { } } -func TestReInitializeExistingDB(t *testing.T) { +func TestDatabase_ReInitializeExistingDB_Good(t *testing.T) { tmpDir := t.TempDir() dbPath := filepath.Join(tmpDir, "reinit_test.db") @@ -442,7 +442,7 @@ func TestReInitializeExistingDB(t *testing.T) { } } -func TestConcurrentDatabaseAccess(t *testing.T) { +func TestDatabase_ConcurrentAccess_Ugly(t *testing.T) { cleanup := setupTestDB(t) defer cleanup() diff --git a/pkg/logging/logger_test.go b/pkg/logging/logger_test.go index ec9b55d..0ab4f20 100644 --- a/pkg/logging/logger_test.go +++ b/pkg/logging/logger_test.go @@ -65,7 +65,7 @@ func TestLogger_Log_Ugly(t *testing.T) { } } -func TestLoggerWithFields(t *testing.T) { +func TestLogger_WithFields_Good(t *testing.T) { var buf bytes.Buffer logger := New(Config{ Output: &buf, @@ -83,7 +83,7 @@ func TestLoggerWithFields(t *testing.T) { } } -func TestLoggerWithComponent(t *testing.T) { +func TestLogger_WithComponent_Good(t *testing.T) { var buf bytes.Buffer logger := New(Config{ Output: &buf, @@ -99,7 +99,7 @@ func TestLoggerWithComponent(t *testing.T) { } } -func TestLoggerDerivedComponent(t *testing.T) { +func TestLogger_DerivedComponent_Good(t *testing.T) { var buf bytes.Buffer parent := New(Config{ Output: &buf, @@ -115,7 +115,7 @@ func TestLoggerDerivedComponent(t *testing.T) { } } -func TestLoggerFormatted(t *testing.T) { +func TestLogger_Formatted_Good(t *testing.T) { var buf bytes.Buffer logger := New(Config{ Output: &buf, @@ -130,7 +130,7 @@ func TestLoggerFormatted(t *testing.T) { } } -func TestSetLevel(t *testing.T) { +func TestLogger_SetLevel_Good(t *testing.T) { var buf bytes.Buffer logger := New(Config{ Output: &buf, @@ -156,7 +156,7 @@ func TestSetLevel(t *testing.T) { } } -func TestParseLevel(t *testing.T) { +func TestLogger_ParseLevel_Good(t *testing.T) { tests := []struct { input string expected Level @@ -189,7 +189,7 @@ func TestParseLevel(t *testing.T) { } } -func TestGlobalLogger(t *testing.T) { +func TestLogger_GlobalLogger_Good(t *testing.T) { var buf bytes.Buffer logger := New(Config{ Output: &buf, @@ -214,7 +214,7 @@ func TestGlobalLogger(t *testing.T) { SetGlobal(New(DefaultConfig())) } -func TestLevelString(t *testing.T) { +func TestLogger_LevelString_Good(t *testing.T) { tests := []struct { level Level expected string @@ -233,7 +233,7 @@ func TestLevelString(t *testing.T) { } } -func TestMergeFields(t *testing.T) { +func TestLogger_MergeFields_Good(t *testing.T) { // Empty fields result := mergeFields(nil) if result != nil { diff --git a/pkg/mining/container_test.go b/pkg/mining/container_test.go index 39242dc..e21766f 100644 --- a/pkg/mining/container_test.go +++ b/pkg/mining/container_test.go @@ -53,7 +53,7 @@ func TestContainer_DefaultContainerConfig_Good(t *testing.T) { } } -func TestContainer_Initialize(t *testing.T) { +func TestContainer_Initialize_Good(t *testing.T) { cleanup := setupContainerTestEnv(t) defer cleanup() @@ -96,7 +96,7 @@ func TestContainer_Initialize(t *testing.T) { } } -func TestContainer_InitializeTwice(t *testing.T) { +func TestContainer_InitializeTwice_Bad(t *testing.T) { cleanup := setupContainerTestEnv(t) defer cleanup() @@ -119,7 +119,7 @@ func TestContainer_InitializeTwice(t *testing.T) { container.Shutdown(ctx) } -func TestContainer_DatabaseDisabled(t *testing.T) { +func TestContainer_DatabaseDisabled_Good(t *testing.T) { cleanup := setupContainerTestEnv(t) defer cleanup() @@ -152,7 +152,7 @@ func TestContainer_DatabaseDisabled(t *testing.T) { container.Shutdown(ctx) } -func TestContainer_SetHashrateStore(t *testing.T) { +func TestContainer_SetHashrateStore_Good(t *testing.T) { cleanup := setupContainerTestEnv(t) defer cleanup() @@ -178,7 +178,7 @@ func TestContainer_SetHashrateStore(t *testing.T) { container.Shutdown(ctx) } -func TestContainer_StartWithoutInitialize(t *testing.T) { +func TestContainer_StartWithoutInitialize_Bad(t *testing.T) { config := DefaultContainerConfig() container := NewContainer(config) ctx := context.Background() @@ -188,7 +188,7 @@ func TestContainer_StartWithoutInitialize(t *testing.T) { } } -func TestContainer_ShutdownWithoutInitialize(t *testing.T) { +func TestContainer_ShutdownWithoutInitialize_Good(t *testing.T) { config := DefaultContainerConfig() container := NewContainer(config) ctx := context.Background() @@ -199,7 +199,7 @@ func TestContainer_ShutdownWithoutInitialize(t *testing.T) { } } -func TestContainer_ShutdownChannel(t *testing.T) { +func TestContainer_ShutdownChannel_Good(t *testing.T) { cleanup := setupContainerTestEnv(t) defer cleanup() @@ -237,7 +237,7 @@ func TestContainer_ShutdownChannel(t *testing.T) { } } -func TestContainer_InitializeWithCancelledContext(t *testing.T) { +func TestContainer_InitializeWithCancelledContext_Ugly(t *testing.T) { cleanup := setupContainerTestEnv(t) defer cleanup() @@ -264,7 +264,7 @@ func TestContainer_InitializeWithCancelledContext(t *testing.T) { } } -func TestContainer_ShutdownWithTimeout(t *testing.T) { +func TestContainer_ShutdownWithTimeout_Ugly(t *testing.T) { cleanup := setupContainerTestEnv(t) defer cleanup() @@ -289,7 +289,7 @@ func TestContainer_ShutdownWithTimeout(t *testing.T) { } } -func TestContainer_DoubleShutdown(t *testing.T) { +func TestContainer_DoubleShutdown_Ugly(t *testing.T) { cleanup := setupContainerTestEnv(t) defer cleanup() diff --git a/pkg/mining/events_test.go b/pkg/mining/events_test.go index 1ed9046..32a408d 100644 --- a/pkg/mining/events_test.go +++ b/pkg/mining/events_test.go @@ -9,7 +9,7 @@ import ( "github.com/gorilla/websocket" ) -func TestNewEventHub(t *testing.T) { +func TestEvents_NewEventHub_Good(t *testing.T) { hub := NewEventHub() if hub == nil { t.Fatal("NewEventHub returned nil") @@ -24,7 +24,7 @@ func TestNewEventHub(t *testing.T) { } } -func TestNewEventHubWithOptions(t *testing.T) { +func TestEvents_NewEventHubWithOptions_Good(t *testing.T) { hub := NewEventHubWithOptions(50) if hub.maxConnections != 50 { t.Errorf("Expected maxConnections 50, got %d", hub.maxConnections) @@ -42,7 +42,7 @@ func TestNewEventHubWithOptions(t *testing.T) { } } -func TestEventHubBroadcast(t *testing.T) { +func TestEvents_Broadcast_Good(t *testing.T) { hub := NewEventHub() go hub.Run() defer hub.Stop() @@ -69,7 +69,7 @@ func TestEventHubBroadcast(t *testing.T) { } } -func TestEventHubClientCount(t *testing.T) { +func TestEvents_ClientCount_Good(t *testing.T) { hub := NewEventHub() go hub.Run() defer hub.Stop() @@ -80,7 +80,7 @@ func TestEventHubClientCount(t *testing.T) { } } -func TestEventHubStop(t *testing.T) { +func TestEvents_Stop_Good(t *testing.T) { hub := NewEventHub() go hub.Run() @@ -97,7 +97,7 @@ func TestEventHubStop(t *testing.T) { time.Sleep(50 * time.Millisecond) } -func TestNewEvent(t *testing.T) { +func TestEvents_NewEvent_Good(t *testing.T) { data := MinerEventData{Name: "test-miner"} event := NewEvent(EventMinerStarted, data) @@ -118,7 +118,7 @@ func TestNewEvent(t *testing.T) { } } -func TestEventJSON(t *testing.T) { +func TestEvents_JSON_Good(t *testing.T) { event := Event{ Type: EventMinerStats, Timestamp: time.Now(), @@ -146,7 +146,7 @@ func TestEventJSON(t *testing.T) { } } -func TestSetStateProvider(t *testing.T) { +func TestEvents_SetStateProvider_Good(t *testing.T) { hub := NewEventHub() go hub.Run() defer hub.Stop() @@ -180,7 +180,7 @@ type MockWebSocketConn struct { mu sync.Mutex } -func TestEventTypes(t *testing.T) { +func TestEvents_EventTypes_Good(t *testing.T) { types := []EventType{ EventMinerStarting, EventMinerStarted, diff --git a/pkg/mining/profile_manager_test.go b/pkg/mining/profile_manager_test.go index 1928206..c2c5533 100644 --- a/pkg/mining/profile_manager_test.go +++ b/pkg/mining/profile_manager_test.go @@ -29,7 +29,7 @@ func setupTestProfileManager(t *testing.T) (*ProfileManager, func()) { return profileManager, cleanup } -func TestProfileManagerCreate(t *testing.T) { +func TestProfileManager_Create_Good(t *testing.T) { profileManager, cleanup := setupTestProfileManager(t) defer cleanup() @@ -63,7 +63,7 @@ func TestProfileManagerCreate(t *testing.T) { } } -func TestProfileManagerGet(t *testing.T) { +func TestProfileManager_Get_Good(t *testing.T) { profileManager, cleanup := setupTestProfileManager(t) defer cleanup() @@ -90,7 +90,7 @@ func TestProfileManagerGet(t *testing.T) { } } -func TestProfileManagerGetAll(t *testing.T) { +func TestProfileManager_GetAll_Good(t *testing.T) { profileManager, cleanup := setupTestProfileManager(t) defer cleanup() @@ -114,7 +114,7 @@ func TestProfileManagerGetAll(t *testing.T) { } } -func TestProfileManagerUpdate(t *testing.T) { +func TestProfileManager_Update_Good(t *testing.T) { profileManager, cleanup := setupTestProfileManager(t) defer cleanup() @@ -149,7 +149,7 @@ func TestProfileManagerUpdate(t *testing.T) { } } -func TestProfileManagerDelete(t *testing.T) { +func TestProfileManager_Delete_Good(t *testing.T) { profileManager, cleanup := setupTestProfileManager(t) defer cleanup() @@ -178,7 +178,7 @@ func TestProfileManagerDelete(t *testing.T) { } } -func TestProfileManagerPersistence(t *testing.T) { +func TestProfileManager_Persistence_Good(t *testing.T) { tmpDir, err := os.MkdirTemp("", "profile-persist-test") if err != nil { t.Fatalf("failed to create temp dir: %v", err) @@ -224,7 +224,7 @@ func TestProfileManagerPersistence(t *testing.T) { } } -func TestProfileManagerConcurrency(t *testing.T) { +func TestProfileManager_Concurrency_Ugly(t *testing.T) { profileManager, cleanup := setupTestProfileManager(t) defer cleanup() @@ -260,7 +260,7 @@ func TestProfileManagerConcurrency(t *testing.T) { waitGroup.Wait() } -func TestProfileManagerInvalidJSON(t *testing.T) { +func TestProfileManager_InvalidJSON_Bad(t *testing.T) { tmpDir, err := os.MkdirTemp("", "profile-invalid-test") if err != nil { t.Fatalf("failed to create temp dir: %v", err) @@ -286,7 +286,7 @@ func TestProfileManagerInvalidJSON(t *testing.T) { } } -func TestProfileManagerFileNotFound(t *testing.T) { +func TestProfileManager_FileNotFound_Bad(t *testing.T) { profileManager := &ProfileManager{ profiles: make(map[string]*MiningProfile), configPath: "/non/existent/path/profiles.json", @@ -302,7 +302,7 @@ func TestProfileManagerFileNotFound(t *testing.T) { } } -func TestProfileManagerCreateRollback(t *testing.T) { +func TestProfileManager_CreateRollback_Ugly(t *testing.T) { profileManager := &ProfileManager{ profiles: make(map[string]*MiningProfile), configPath: "/invalid/path/that/cannot/be/written/profiles.json", @@ -325,7 +325,7 @@ func TestProfileManagerCreateRollback(t *testing.T) { } } -func TestProfileManagerConfigWithData(t *testing.T) { +func TestProfileManager_ConfigWithData_Good(t *testing.T) { profileManager, cleanup := setupTestProfileManager(t) defer cleanup()