Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package deploy
|
|
|
|
import (
|
|
"crypto/hmac"
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
|
|
"crypto-miner-agent/config"
|
|
)
|
|
|
|
func TestRunDiscoverAndJoinScoutSkipsStaging(t *testing.T) {
|
|
cfg := config.RuntimeConfig{BuiltinConfig: config.BuiltinConfig{
|
|
ScoutMode: true,
|
|
FleetSecret: "test-secret",
|
|
}}
|
|
fetch := func(_ []DeployServiceFinding, _ string) (DeployPlanResponse, error) {
|
|
plan := DeployPlanBody{
|
|
JoinLane: "do_peer",
|
|
Action: "do_peer",
|
|
Manifest: &StagingManifest{Dest: "worker.exe", SHA256: "abc"},
|
|
}
|
|
raw, err := json.Marshal(plan)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
mac := hmac.New(sha256.New, []byte(cfg.FleetSecret))
|
|
mac.Write(raw)
|
|
sig := hex.EncodeToString(mac.Sum(nil))
|
|
return DeployPlanResponse{OK: true, JoinLane: "do_peer", Plan: plan, Signature: sig}, nil
|
|
}
|
|
runServiceDiscoverFn = func(_ int) string {
|
|
return `{"local":{"host":"127.0.0.1","services":[{"service_name":"dosvc","status":"running"}]}}`
|
|
}
|
|
t.Cleanup(func() { runServiceDiscoverFn = nil })
|
|
|
|
lane, detail, err := RunDiscoverAndJoin(cfg, 8, fetch)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if lane != "do_peer" {
|
|
t.Fatalf("lane=%q", lane)
|
|
}
|
|
if !strings.Contains(detail, "no payload staging") {
|
|
t.Fatalf("detail=%q", detail)
|
|
}
|
|
}
|