Files
Reims-Go/internal/plugin/builtin/downloader_test.go
T

54 lines
1.6 KiB
Go

package builtin
import (
"context"
"testing"
"github.com/Nwflower/reims-go/internal/downloader"
"github.com/Nwflower/reims-go/internal/plugin"
)
func TestDownloaderParallelPluginLifecycle(t *testing.T) {
reg := plugin.NewRegistry(nil)
settings := map[string]any{
"proxy_mode": downloader.ProxyModeDirect,
"connections": "16",
"stall_timeout_sec": 20,
}
cb := HostCallbacks{
GetSetting: func(pluginID, vmName, key string) (any, bool) {
if pluginID != IDDownloaderParallel || vmName != "" {
return nil, false
}
v, ok := settings[key]
return v, ok
},
}
if err := RegisterAll(reg, cb, nil); err != nil {
t.Fatalf("RegisterAll: %v", err)
}
reg.Reconcile(context.Background())
contrib, prov, ok := reg.ActiveDownloader()
if !ok || prov == nil {
t.Fatal("expected active builtin downloader after Reconcile")
}
if contrib.ID != IDDownloaderParallel || prov.ID() != IDDownloaderParallel {
t.Fatalf("unexpected active downloader: contrib=%q prov=%q", contrib.ID, prov.ID())
}
opts := readParallelDownloaderOpts(cb)
if opts.ProxyMode != downloader.ProxyModeDirect || opts.Connections != 16 || opts.StallTimeout.Seconds() != 20 {
t.Fatalf("unexpected parsed options: %+v", opts)
}
// Disabling the plugin must cleanly dispose the registered downloader.
if err := reg.SetDesired(context.Background(), IDDownloaderParallel, false); err != nil {
t.Fatalf("SetDesired(false): %v", err)
}
reg.Reconcile(context.Background())
if _, _, ok := reg.ActiveDownloader(); ok {
t.Fatal("expected no active downloader after disabling plugin")
}
}