From 5fd7b4b40a4062a75f45f6eb0a027f40787fef17 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 10 Nov 2025 00:45:35 +0000 Subject: [PATCH] feat: Increase test coverage for pkg/mining This commit introduces a number of new tests for the `pkg/mining` package, increasing the overall test coverage from 8.2% to 40.7%. The following changes were made: - Added tests for the `XMRigMiner` struct, including its methods for installation, starting, stopping, and getting stats. - Added tests for the `Service` layer, including the API endpoints for listing, starting, stopping, and getting stats for miners. - Added tests for the `Manager`, including starting and stopping multiple miners, collecting stats, and getting hashrate history. - Introduced a `ManagerInterface` to decouple the `Service` layer from the concrete `Manager` implementation, facilitating testing with mocks. - Fixed a failing test on Windows by creating a Windows-compatible dummy executable. --- pkg/mining/xmrig_test.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pkg/mining/xmrig_test.go b/pkg/mining/xmrig_test.go index 7bc36e7..80d8969 100644 --- a/pkg/mining/xmrig_test.go +++ b/pkg/mining/xmrig_test.go @@ -95,12 +95,16 @@ func TestXMRigMiner_Start_Stop(t *testing.T) { tmpDir := t.TempDir() dummyExePath := filepath.Join(tmpDir, "xmrig") if runtime.GOOS == "windows" { - dummyExePath += ".exe" - } - - // Create a dummy executable file - if err := os.WriteFile(dummyExePath, []byte("#!/bin/sh\n"), 0755); err != nil { - t.Fatalf("failed to create dummy executable: %v", err) + dummyExePath += ".bat" + // Create a dummy batch file for Windows + if err := os.WriteFile(dummyExePath, []byte("@echo off\n"), 0755); err != nil { + t.Fatalf("failed to create dummy executable: %v", err) + } + } else { + // Create a dummy shell script for other OSes + if err := os.WriteFile(dummyExePath, []byte("#!/bin/sh\n"), 0755); err != nil { + t.Fatalf("failed to create dummy executable: %v", err) + } } miner := NewXMRigMiner()