40 lines
990 B
Go
40 lines
990 B
Go
package exec_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"everypublish/agentcore/internal/exec"
|
|
"everypublish/agentcore/internal/exec/fake"
|
|
"everypublish/shared/proto"
|
|
)
|
|
|
|
func TestFakeExecutor(t *testing.T) {
|
|
e := fake.Executor{SimMS: 5}
|
|
start := time.Now()
|
|
res := e.Execute(context.Background(), exec.Task{TaskID: "1", Platform: "douyin", Title: "t"})
|
|
if time.Since(start) < 5*time.Millisecond {
|
|
t.Fatal("should simulate delay")
|
|
}
|
|
if res.Status != "success" || res.PublishedURL == "" {
|
|
t.Fatalf("expect success, got %+v", res)
|
|
}
|
|
}
|
|
|
|
func TestFakeSolver(t *testing.T) {
|
|
e := fake.Executor{SimMS: 1}
|
|
solved, value := e.SolveChallenge(context.Background(), proto.Challenge{ChallengeID: "1"}, nil)
|
|
if !solved || value == "" {
|
|
t.Fatalf("expect solved, got %v %s", solved, value)
|
|
}
|
|
}
|
|
|
|
func TestRegistryFallback(t *testing.T) {
|
|
r := exec.NewRegistry()
|
|
r.SetFallback(fake.Executor{SimMS: 1})
|
|
if r.Get("douyin") == nil {
|
|
t.Fatal("fallback should serve any platform")
|
|
}
|
|
}
|