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.
This commit is contained in:
google-labs-jules[bot] 2025-11-10 00:45:35 +00:00
parent 0f8f61071e
commit 5fd7b4b40a

View file

@ -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()