Mining/pkg/mining/profile_manager_test.go
google-labs-jules[bot] b2c8014e42 Fix backend and frontend tests after major refactoring
- Fix `MockManager` in `pkg/mining/service_test.go` to implement `UninstallMiner`.
- Fix `XMRigMiner` struct literals in tests to use embedded `BaseMiner`.
- Update `XMRigSummary` struct usage and fix history method calls in `pkg/mining/xmrig_test.go`.
- Isolate `xdg` configuration in `pkg/mining/manager_test.go` and clean up miner state to fix leakage.
- Fix `TestStartMiner_Ugly` logic by using `Algo` for deterministic naming.
- Add `pkg/mining/profile_manager_test.go` to cover `ProfileManager`.
- Remove obsolete `TestHandleStartMiner` in `pkg/mining/service_test.go`.
- Fix UI test compilation by updating component import to `SniderMining` and mocking `MinerService` with signals.
2025-12-11 16:28:42 +00:00

76 lines
1.6 KiB
Go

package mining
import (
"encoding/json"
"testing"
"github.com/adrg/xdg"
)
func TestProfileManager(t *testing.T) {
// Isolate config directory for this test
tempConfigDir := t.TempDir()
origConfigHome := xdg.ConfigHome
xdg.ConfigHome = tempConfigDir
t.Cleanup(func() {
xdg.ConfigHome = origConfigHome
})
pm, err := NewProfileManager()
if err != nil {
t.Fatalf("Failed to create ProfileManager: %v", err)
}
// Create
config := Config{Wallet: "test"}
configBytes, _ := json.Marshal(config)
profile := &MiningProfile{
Name: "Test Profile",
MinerType: "xmrig",
Config: RawConfig(configBytes),
}
created, err := pm.CreateProfile(profile)
if err != nil {
t.Fatalf("Failed to create profile: %v", err)
}
if created.ID == "" {
t.Error("Created profile has empty ID")
}
// Get
got, exists := pm.GetProfile(created.ID)
if !exists {
t.Error("Failed to get profile")
}
if got.Name != "Test Profile" {
t.Errorf("Expected name 'Test Profile', got '%s'", got.Name)
}
// List
all := pm.GetAllProfiles()
if len(all) != 1 {
t.Errorf("Expected 1 profile, got %d", len(all))
}
// Update
created.Name = "Updated Profile"
err = pm.UpdateProfile(created)
if err != nil {
t.Fatalf("Failed to update profile: %v", err)
}
got, _ = pm.GetProfile(created.ID)
if got.Name != "Updated Profile" {
t.Errorf("Expected name 'Updated Profile', got '%s'", got.Name)
}
// Delete
err = pm.DeleteProfile(created.ID)
if err != nil {
t.Fatalf("Failed to delete profile: %v", err)
}
_, exists = pm.GetProfile(created.ID)
if exists {
t.Error("Profile should have been deleted")
}
}