* refactor: 收拢核心管线、强化错误处理、优化热路径与更新体积 * fix: preserve download recovery and bound PBZX decoding Keep VM diagnostics available during plugin initialization failures and verify settings through the unified driver lifecycle.
546 lines
17 KiB
Go
546 lines
17 KiB
Go
package plugin
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"reflect"
|
|
"strings"
|
|
"sync/atomic"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestSemVerMatchesRange(t *testing.T) {
|
|
cases := []struct {
|
|
ver string
|
|
expr string
|
|
want bool
|
|
}{
|
|
{"1.0.0", "^1.0.0", true},
|
|
{"1.5.2", "^1.0.0", true},
|
|
{"2.0.0", "^1.0.0", false},
|
|
{"1.2.5", "~1.2.0", true},
|
|
{"1.3.0", "~1.2.0", false},
|
|
{"0.2.6", ">=0.2.0 <0.3.0", true},
|
|
{"0.3.0", ">=0.2.0 <0.3.0", false},
|
|
{"1.0.0", "1.x", true},
|
|
{"2.0.0", "1.x || >=2.0.0", true},
|
|
{"0.9.0", "", true},
|
|
{"1.0.0-alpha.1", ">=1.0.0", false},
|
|
}
|
|
for _, tc := range cases {
|
|
if got := MatchesRange(tc.ver, tc.expr); got != tc.want {
|
|
t.Errorf("MatchesRange(%q, %q) = %v, want %v", tc.ver, tc.expr, got, tc.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestScopeLIFODisposeAndPanicSafety(t *testing.T) {
|
|
reg := NewRegistry(nil)
|
|
sc := newScope("test.plugin", reg)
|
|
var order []int
|
|
sc.OnDispose(func() { order = append(order, 1) })
|
|
sc.OnDispose(func() { panic("cleanup boom") })
|
|
sc.OnDispose(func() { order = append(order, 3) })
|
|
|
|
sc.Dispose()
|
|
sc.Dispose() // idempotent
|
|
|
|
want := []int{3, 1}
|
|
if !reflect.DeepEqual(order, want) {
|
|
t.Fatalf("dispose order = %v, want %v", order, want)
|
|
}
|
|
}
|
|
|
|
func TestRegistryDependencyReconcileAndCascade(t *testing.T) {
|
|
reg := NewRegistry(nil)
|
|
var log []string
|
|
|
|
_ = reg.Register(PluginDef{
|
|
Manifest: Manifest{
|
|
ID: "builtin.transport",
|
|
Version: "1.0.0",
|
|
Provides: []ServiceProvision{{Service: "transport", Version: "1.0.0"}},
|
|
},
|
|
Source: SourceBuiltin,
|
|
Trust: TrustOfficial,
|
|
Desired: true,
|
|
Activate: func(_ context.Context, sc *Scope) error {
|
|
log = append(log, "up:transport")
|
|
sc.Provide("transport", "1.0.0", "svc-instance")
|
|
sc.OnDispose(func() { log = append(log, "down:transport") })
|
|
return nil
|
|
},
|
|
})
|
|
_ = reg.Register(PluginDef{
|
|
Manifest: Manifest{
|
|
ID: "builtin.clipboard",
|
|
Version: "1.0.0",
|
|
Requires: []ServiceRequirement{{Service: "transport", Version: "^1.0.0"}},
|
|
},
|
|
Source: SourceBuiltin,
|
|
Trust: TrustOfficial,
|
|
Desired: true,
|
|
Activate: func(_ context.Context, sc *Scope) error {
|
|
svc, ok := sc.Lookup("transport")
|
|
if !ok || svc != "svc-instance" {
|
|
return errors.New("missing transport service")
|
|
}
|
|
log = append(log, "up:clipboard")
|
|
sc.OnDispose(func() { log = append(log, "down:clipboard") })
|
|
return nil
|
|
},
|
|
})
|
|
|
|
reg.Reconcile(context.Background())
|
|
if !reg.IsActive("builtin.transport") || !reg.IsActive("builtin.clipboard") {
|
|
t.Fatalf("expected both active, got transport=%s clipboard=%s", reg.StateOf("builtin.transport"), reg.StateOf("builtin.clipboard"))
|
|
}
|
|
|
|
// Disabling provider must cascade-dispose dependent and leave it pending.
|
|
if err := reg.SetDesired(context.Background(), "builtin.transport", false); err != nil {
|
|
t.Fatalf("disable transport: %v", err)
|
|
}
|
|
if reg.IsActive("builtin.transport") {
|
|
t.Fatal("transport should be off")
|
|
}
|
|
if reg.IsActive("builtin.clipboard") {
|
|
t.Fatal("clipboard should have been cascade-disposed")
|
|
}
|
|
if reg.StateOf("builtin.clipboard") != StatePending {
|
|
t.Fatalf("clipboard state = %s, want pending", reg.StateOf("builtin.clipboard"))
|
|
}
|
|
if want := []string{"up:transport", "up:clipboard", "down:clipboard", "down:transport"}; !reflect.DeepEqual(log, want) {
|
|
t.Fatalf("lifecycle order = %v, want %v", log, want)
|
|
}
|
|
|
|
// Re-enabling provider automatically reactivates pending dependent.
|
|
if err := reg.SetDesired(context.Background(), "builtin.transport", true); err != nil {
|
|
t.Fatalf("re-enable transport: %v", err)
|
|
}
|
|
if !reg.IsActive("builtin.clipboard") {
|
|
t.Fatalf("clipboard should auto-reactivate, got %s", reg.StateOf("builtin.clipboard"))
|
|
}
|
|
}
|
|
|
|
func TestRegistryDisposesTransitiveRequiredConsumersBeforePublishedProvider(t *testing.T) {
|
|
reg := NewRegistry(nil)
|
|
ctx := context.Background()
|
|
const (
|
|
shadowed = "builtin.legacy-transport"
|
|
provider = "builtin.transport"
|
|
bridge = "builtin.bridge"
|
|
viewer = "builtin.viewer"
|
|
optional = "builtin.optional"
|
|
)
|
|
var disposed []string
|
|
register := func(id, service string, requirements ...ServiceRequirement) {
|
|
t.Helper()
|
|
def := PluginDef{
|
|
Manifest: Manifest{ID: id, Version: "1.0.0", Requires: requirements},
|
|
Source: SourceBuiltin,
|
|
Trust: TrustOfficial,
|
|
Desired: true,
|
|
Activate: func(_ context.Context, sc *Scope) error {
|
|
if service != "" {
|
|
sc.Provide(service, "1.0.0", id)
|
|
}
|
|
sc.OnDispose(func() {
|
|
for _, req := range requirements {
|
|
if _, ok := sc.Lookup(req.Service); !req.Optional && !ok {
|
|
t.Errorf("%s lost %s before its disposer ran", id, req.Service)
|
|
}
|
|
}
|
|
disposed = append(disposed, id)
|
|
})
|
|
return nil
|
|
},
|
|
}
|
|
if err := reg.Register(def); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
register(shadowed, "transport")
|
|
register(provider, "transport")
|
|
register(bridge, "bridge", ServiceRequirement{Service: "transport"})
|
|
register(viewer, "", ServiceRequirement{Service: "bridge"})
|
|
register(optional, "", ServiceRequirement{Service: "transport", Optional: true})
|
|
reg.Reconcile(ctx)
|
|
|
|
if svc, ok := reg.LookupService("transport"); !ok || svc != provider || !reg.IsActive(viewer) {
|
|
t.Fatalf("expected active consumer using published provider, service=%v consumer=%s", svc, reg.StateOf(viewer))
|
|
}
|
|
if err := reg.SetDesired(ctx, shadowed, false); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !reflect.DeepEqual(disposed, []string{shadowed}) || !reg.IsActive(viewer) {
|
|
t.Fatalf("disabling shadowed provider affected consumer, disposed=%v", disposed)
|
|
}
|
|
if err := reg.SetDesired(ctx, provider, false); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if want := []string{shadowed, viewer, bridge, provider}; !reflect.DeepEqual(disposed, want) {
|
|
t.Fatalf("disposal order = %v, want %v", disposed, want)
|
|
}
|
|
if reg.StateOf(viewer) != StatePending || reg.StateOf(bridge) != StatePending ||
|
|
reg.StateOf(provider) != StateOff || !reg.IsActive(optional) {
|
|
t.Fatalf("unexpected final states: viewer=%s bridge=%s provider=%s optional=%s",
|
|
reg.StateOf(viewer), reg.StateOf(bridge), reg.StateOf(provider), reg.StateOf(optional))
|
|
}
|
|
}
|
|
|
|
func TestRegistryPanicRollbackAndInUseFailClosed(t *testing.T) {
|
|
reg := NewRegistry(nil)
|
|
rolledBack := false
|
|
_ = reg.Register(PluginDef{
|
|
Manifest: Manifest{ID: "bad.panic", Version: "1.0.0"},
|
|
Source: SourceLocal,
|
|
Desired: true,
|
|
Activate: func(_ context.Context, sc *Scope) error {
|
|
sc.OnDispose(func() { rolledBack = true })
|
|
sc.Provide("temp.svc", "1.0.0", 42)
|
|
panic("boom")
|
|
},
|
|
})
|
|
_ = reg.Register(PluginDef{
|
|
Manifest: Manifest{
|
|
ID: "bad.api",
|
|
Version: "1.0.0",
|
|
Engines: Engines{PluginAPI: "^9.0.0"},
|
|
},
|
|
Source: SourceLocal,
|
|
Desired: true,
|
|
})
|
|
reg.Reconcile(context.Background())
|
|
|
|
if !rolledBack {
|
|
t.Fatal("expected activation panic to roll back scope")
|
|
}
|
|
if _, ok := reg.LookupService("temp.svc"); ok {
|
|
t.Fatal("expected provided service to be rolled back on panic")
|
|
}
|
|
if reg.StateOf("bad.panic") != StateFailed {
|
|
t.Fatalf("bad.panic state = %s, want failed", reg.StateOf("bad.panic"))
|
|
}
|
|
if reg.StateOf("bad.api") != StateFailed {
|
|
t.Fatalf("bad.api state = %s, want failed", reg.StateOf("bad.api"))
|
|
}
|
|
|
|
// InUse fail-closed guard.
|
|
_ = reg.Register(PluginDef{
|
|
Manifest: Manifest{ID: "drv.test", Version: "1.0.0"},
|
|
Source: SourceLocal,
|
|
Desired: true,
|
|
})
|
|
reg.Reconcile(context.Background())
|
|
reg.SetBusyChecker(func(id string) (bool, string, error) {
|
|
if id == "drv.test" {
|
|
return false, "", errors.New("probe error")
|
|
}
|
|
return false, "", nil
|
|
})
|
|
if err := reg.SetDesired(context.Background(), "drv.test", false); err == nil {
|
|
t.Fatal("expected fail-closed error when BusyChecker fails")
|
|
}
|
|
reg.SetBusyChecker(func(string) (bool, string, error) { return true, "VM a is running", nil })
|
|
if err := reg.SetDesired(context.Background(), "drv.test", false); err == nil {
|
|
t.Fatal("expected disabling to be refused while a VM runs")
|
|
}
|
|
|
|
// Owning stopped VMs blocks removal, not disabling: the VMs stay on disk
|
|
// as driver_unavailable until the plugin is enabled again.
|
|
reg.SetBusyChecker(func(string) (bool, string, error) { return false, "", nil })
|
|
reg.SetInUseChecker(func(id string) (bool, string, error) { return id == "drv.test", "VM a owned by drv.test", nil })
|
|
if err := reg.SetDesired(context.Background(), "drv.test", false); err != nil {
|
|
t.Fatalf("disabling a plugin with stopped VMs: %v", err)
|
|
}
|
|
if reg.StateOf("drv.test") == StateActive {
|
|
t.Fatal("drv.test still active after disabling")
|
|
}
|
|
if err := reg.Unregister(context.Background(), "drv.test"); err == nil {
|
|
t.Fatal("expected removal to be refused while the plugin owns VMs")
|
|
}
|
|
reg.SetInUseChecker(func(string) (bool, string, error) { return false, "", errors.New("probe error") })
|
|
if err := reg.Unregister(context.Background(), "drv.test"); err == nil {
|
|
t.Fatal("expected fail-closed removal when InUseChecker fails")
|
|
}
|
|
}
|
|
|
|
func TestHookBusOrderingTimeoutDegradeAndBlocking(t *testing.T) {
|
|
reg := NewRegistry(nil)
|
|
var seq []string
|
|
_ = reg.Register(PluginDef{
|
|
Manifest: Manifest{ID: "user.hook", Version: "1.0.0"},
|
|
Source: SourceLocal,
|
|
Desired: true,
|
|
Activate: func(_ context.Context, sc *Scope) error {
|
|
reg.Hooks().Subscribe(sc, HookRegistration{
|
|
Event: EventVMBeforeStart,
|
|
Handler: func(_ context.Context, _ any) (any, error) {
|
|
seq = append(seq, "user")
|
|
return StartIntent{Warnings: []string{"user-warn"}}, nil
|
|
},
|
|
})
|
|
return nil
|
|
},
|
|
})
|
|
_ = reg.Register(PluginDef{
|
|
Manifest: Manifest{ID: "builtin.hook", Version: "1.0.0"},
|
|
Source: SourceBuiltin,
|
|
Desired: true,
|
|
Activate: func(_ context.Context, sc *Scope) error {
|
|
reg.Hooks().Subscribe(sc, HookRegistration{
|
|
Event: EventVMBeforeStart,
|
|
Builtin: true,
|
|
Handler: func(_ context.Context, _ any) (any, error) {
|
|
seq = append(seq, "builtin")
|
|
return StartIntent{Warnings: []string{"builtin-warn"}}, nil
|
|
},
|
|
})
|
|
return nil
|
|
},
|
|
})
|
|
var failCalls atomic.Int32
|
|
_ = reg.Register(PluginDef{
|
|
Manifest: Manifest{ID: "flaky.hook", Version: "1.0.0"},
|
|
Source: SourceLocal,
|
|
Desired: true,
|
|
Activate: func(_ context.Context, sc *Scope) error {
|
|
reg.Hooks().Subscribe(sc, HookRegistration{
|
|
Event: EventHostPreflight,
|
|
Handler: func(_ context.Context, _ any) (any, error) {
|
|
failCalls.Add(1)
|
|
return nil, errors.New("boom")
|
|
},
|
|
})
|
|
return nil
|
|
},
|
|
})
|
|
reg.Reconcile(context.Background())
|
|
|
|
intents, err := reg.Hooks().DispatchBeforeStart(context.Background(), BeforeStartPayload{VMName: "vm1"})
|
|
if err != nil {
|
|
t.Fatalf("DispatchBeforeStart error: %v", err)
|
|
}
|
|
if !reflect.DeepEqual(seq, []string{"builtin", "user"}) {
|
|
t.Fatalf("hook order = %v, want [builtin user]", seq)
|
|
}
|
|
if len(intents) != 2 {
|
|
t.Fatalf("intents len = %d, want 2", len(intents))
|
|
}
|
|
|
|
// 3 consecutive failures degrade the plugin.
|
|
for i := 0; i < 3; i++ {
|
|
reg.Hooks().DispatchPreflight(context.Background(), PreflightPayload{})
|
|
}
|
|
if reg.StateOf("flaky.hook") != StateDegraded {
|
|
t.Fatalf("flaky.hook state = %s, want degraded", reg.StateOf("flaky.hook"))
|
|
}
|
|
|
|
// Blocking guard honored only when Blocking && BlockingAllowed.
|
|
_ = reg.Register(PluginDef{
|
|
Manifest: Manifest{ID: "guard.block", Version: "1.0.0", Permissions: []string{"vm:intent"}},
|
|
Source: SourceLocal,
|
|
Desired: true,
|
|
Activate: func(_ context.Context, sc *Scope) error {
|
|
reg.Hooks().Subscribe(sc, HookRegistration{
|
|
Event: EventVMBeforeStart,
|
|
Blocking: true,
|
|
BlockingAllowed: true,
|
|
Handler: func(_ context.Context, _ any) (any, error) {
|
|
return StartIntent{BlockReason: "policy check failed"}, nil
|
|
},
|
|
})
|
|
return nil
|
|
},
|
|
})
|
|
reg.Reconcile(context.Background())
|
|
if _, err := reg.Hooks().DispatchBeforeStart(context.Background(), BeforeStartPayload{VMName: "vm1"}); err == nil || !strings.Contains(err.Error(), "policy check failed") {
|
|
t.Fatalf("expected blocking error, got %v", err)
|
|
}
|
|
|
|
// Zero-overhead log.onLine check.
|
|
if reg.Hooks().HasSubscribers(EventLogOnLine) {
|
|
t.Fatal("expected no log.onLine subscribers")
|
|
}
|
|
reg.Hooks().EmitLogLine("vm1", "qemu", "fast path")
|
|
}
|
|
|
|
func TestArgLedgerReconcilePreserveUserArgsAndStripOnDisable(t *testing.T) {
|
|
dir := t.TempDir()
|
|
ledger, err := LoadArgLedger(dir)
|
|
if err != nil {
|
|
t.Fatalf("LoadArgLedger: %v", err)
|
|
}
|
|
|
|
// User has hand-written args that must NEVER be stripped.
|
|
userArgs := `-device virtio-rng-pci -rtc base=utc`
|
|
active := map[string]bool{
|
|
"builtin.compat.whpx-fallback": true,
|
|
"thirdparty.tweak": true,
|
|
}
|
|
intents := []StartIntent{
|
|
{
|
|
PluginID: "builtin.compat.whpx-fallback",
|
|
Args: []ArgFragment{{
|
|
Key: "kernel-irqchip",
|
|
Tokens: []string{"-machine", "kernel-irqchip=off"},
|
|
Builtin: true,
|
|
Priority: 100,
|
|
}},
|
|
},
|
|
{
|
|
PluginID: "thirdparty.tweak",
|
|
Args: []ArgFragment{
|
|
{
|
|
Key: "kernel-irqchip", // conflicts with builtin; builtin wins!
|
|
Tokens: []string{"-machine", "kernel-irqchip=on"},
|
|
Priority: 999,
|
|
},
|
|
{
|
|
Key: "disallowed",
|
|
Tokens: []string{"-smbios", "type=1,serial=FAKE"}, // rejected by allowlist
|
|
},
|
|
{
|
|
Key: "custom-dev",
|
|
Tokens: []string{"-device", "usb-tablet,id=my-tab"},
|
|
},
|
|
},
|
|
Env: map[string]string{
|
|
"REIMS_PLUGIN_THIRDPARTY_TWEAK_DEBUG": "1",
|
|
"PATH": "/hijack", // rejected
|
|
},
|
|
},
|
|
}
|
|
|
|
res := ReconcileStartIntentsForDriver(userArgs, ledger, active, "", intents)
|
|
if !strings.Contains(res.ExtraArgs, "-device virtio-rng-pci -rtc base=utc") {
|
|
t.Fatalf("user args lost: %q", res.ExtraArgs)
|
|
}
|
|
if !strings.Contains(res.ExtraArgs, "-machine kernel-irqchip=off") {
|
|
t.Fatalf("builtin winning arg missing: %q", res.ExtraArgs)
|
|
}
|
|
if strings.Contains(res.ExtraArgs, "kernel-irqchip=on") {
|
|
t.Fatalf("losing conflict arg should not appear: %q", res.ExtraArgs)
|
|
}
|
|
if strings.Contains(res.ExtraArgs, "-smbios") {
|
|
t.Fatalf("disallowed -smbios arg should be rejected: %q", res.ExtraArgs)
|
|
}
|
|
if !strings.Contains(res.ExtraArgs, "-device usb-tablet,id=my-tab") {
|
|
t.Fatalf("valid plugin arg missing: %q", res.ExtraArgs)
|
|
}
|
|
if len(res.Env) != 1 || res.Env[0] != "REIMS_PLUGIN_THIRDPARTY_TWEAK_DEBUG=1" {
|
|
t.Fatalf("unexpected env: %v", res.Env)
|
|
}
|
|
if len(res.Warnings) < 3 {
|
|
t.Fatalf("expected conflict, disallowed arg, and disallowed env warnings, got %v", res.Warnings)
|
|
}
|
|
|
|
if err := SaveArgLedger(dir, ledger); err != nil {
|
|
t.Fatalf("SaveArgLedger: %v", err)
|
|
}
|
|
reloaded, err := LoadArgLedger(dir)
|
|
if err != nil {
|
|
t.Fatalf("reload ledger: %v", err)
|
|
}
|
|
|
|
// Disable thirdparty.tweak -> its fragment is stripped cleanly, user + builtin remain.
|
|
delete(active, "thirdparty.tweak")
|
|
after := ReconcileStartIntentsForDriver(res.ExtraArgs, reloaded, active, "", intents[:1])
|
|
if !after.Changed {
|
|
t.Fatal("expected change on strip")
|
|
}
|
|
stripped := after.ExtraArgs
|
|
if strings.Contains(stripped, "usb-tablet") {
|
|
t.Fatalf("plugin fragment not stripped: %q", stripped)
|
|
}
|
|
if !strings.Contains(stripped, "-device virtio-rng-pci -rtc base=utc") || !strings.Contains(stripped, "-machine kernel-irqchip=off") {
|
|
t.Fatalf("user or builtin args damaged: %q", stripped)
|
|
}
|
|
}
|
|
|
|
func TestL1RuleHooks(t *testing.T) {
|
|
reg := NewRegistry(nil)
|
|
_ = reg.Register(PluginDef{
|
|
Manifest: Manifest{
|
|
ID: "l1.rule.sample",
|
|
Version: "1.0.0",
|
|
Permissions: []string{"vm:intent"},
|
|
Contributes: Contributes{
|
|
RuleHooks: []RuleHook{{
|
|
ID: "rtc-rule",
|
|
Event: EventVMBeforeStart,
|
|
Conditions: []RuleCondition{
|
|
{Fact: "vm.driver", Operator: "eq", Value: "builtin.driver.reims-macos"},
|
|
{Fact: "runtime.capabilities", Operator: "not_contains", Value: "rtc-fix"},
|
|
},
|
|
Actions: []RuleAction{
|
|
{Kind: "append_args", Key: "rtc", Tokens: []string{"-rtc", "base=localtime"}},
|
|
{Kind: "warn", Message: LocalizedText{ZhCN: "已应用 RTC 规则", EnUS: "applied rtc rule"}},
|
|
},
|
|
}},
|
|
},
|
|
},
|
|
Source: SourceLocal,
|
|
Desired: true,
|
|
})
|
|
reg.Reconcile(context.Background())
|
|
|
|
intents, err := reg.Hooks().DispatchBeforeStart(context.Background(), BeforeStartPayload{
|
|
VMName: "vm1",
|
|
DriverID: "builtin.driver.reims-macos",
|
|
RuntimeCaps: []string{"win10-compat"},
|
|
})
|
|
if err != nil || len(intents) != 1 || len(intents[0].Args) != 1 {
|
|
t.Fatalf("expected 1 rule intent with 1 arg, got intents=%+v err=%v", intents, err)
|
|
}
|
|
|
|
// Now with runtime having "rtc-fix", rule should not match.
|
|
intents2, _ := reg.Hooks().DispatchBeforeStart(context.Background(), BeforeStartPayload{
|
|
VMName: "vm1",
|
|
DriverID: "builtin.driver.reims-macos",
|
|
RuntimeCaps: []string{"rtc-fix"},
|
|
})
|
|
if len(intents2) != 0 {
|
|
t.Fatalf("expected 0 intents when cap present, got %+v", intents2)
|
|
}
|
|
}
|
|
|
|
func TestLogLineBatchDelivery(t *testing.T) {
|
|
reg := NewRegistry(nil)
|
|
received := make(chan []LogLineEvent, 1)
|
|
_ = reg.Register(PluginDef{
|
|
Manifest: Manifest{ID: "log.sub", Version: "1.0.0"},
|
|
Source: SourceLocal,
|
|
Desired: true,
|
|
Activate: func(_ context.Context, sc *Scope) error {
|
|
reg.Hooks().Subscribe(sc, HookRegistration{
|
|
Event: EventLogOnLine,
|
|
Handler: func(_ context.Context, raw any) (any, error) {
|
|
if batch, ok := raw.([]LogLineEvent); ok {
|
|
select {
|
|
case received <- batch:
|
|
default:
|
|
}
|
|
}
|
|
return nil, nil
|
|
},
|
|
})
|
|
return nil
|
|
},
|
|
})
|
|
reg.Reconcile(context.Background())
|
|
if !reg.Hooks().HasSubscribers(EventLogOnLine) {
|
|
t.Fatal("expected log subscriber")
|
|
}
|
|
reg.Hooks().EmitLogLine("vm1", "serial", "hello kernel")
|
|
select {
|
|
case batch := <-received:
|
|
if len(batch) != 1 || batch[0].Line != "hello kernel" {
|
|
t.Fatalf("unexpected batch: %+v", batch)
|
|
}
|
|
case <-time.After(2 * time.Second):
|
|
t.Fatal("timed out waiting for batched log.onLine")
|
|
}
|
|
}
|