Every VM action had two bindings: one by name and one by driver and name. The window used only the second, so the first is gone and the WithDriver suffix with it. Unused bindings and frontend exports are removed too. Tests now reject bindings the window never calls, stale generated bindings and unused frontend exports. TypeScript rejects unused locals. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
75 lines
2.3 KiB
Go
75 lines
2.3 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/Nwflower/reims-go/internal/config"
|
|
"github.com/Nwflower/reims-go/internal/driver"
|
|
"github.com/Nwflower/reims-go/internal/guesttools"
|
|
vmlifecycle "github.com/Nwflower/reims-go/internal/lifecycle"
|
|
"github.com/Nwflower/reims-go/internal/plugin"
|
|
)
|
|
|
|
func TestVMStatsReportsLiveGuestToolsAgentVersion(t *testing.T) {
|
|
cfg := &config.Config{DataRoot: t.TempDir()}
|
|
srv := guesttools.NewTransportServer(nil)
|
|
port, err := srv.Start(-1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(func() { srv.Close(context.Background()) })
|
|
const name = "mac"
|
|
const token = "test-token"
|
|
srv.RegisterVM(guesttools.VMConfig{VMName: name, Token: token})
|
|
drv := &appSecondDriver{
|
|
id: driver.BuiltinReimsMacOSDriverID,
|
|
vms: []driver.VMInfo{{Name: name, DriverID: driver.BuiltinReimsMacOSDriverID, Directory: cfg.DataRoot, State: "running"}},
|
|
}
|
|
reg := plugin.NewRegistry(nil)
|
|
if err := reg.Register(plugin.PluginDef{
|
|
Manifest: plugin.Manifest{ID: "test.macos", Version: "1.0.0"},
|
|
Source: plugin.SourceBuiltin,
|
|
Desired: true,
|
|
Activate: func(_ context.Context, sc *plugin.Scope) error {
|
|
reg.RegisterGuestDriver(sc, drv.id, drv)
|
|
return nil
|
|
},
|
|
}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
reg.Reconcile(context.Background())
|
|
router := driver.NewRouter(reg, nil)
|
|
now := time.Now()
|
|
a := &App{cfg: cfg, guestTools: srv, lastVMsAt: now, lifecycleSvc: vmlifecycle.New(reg, router, nil)}
|
|
for _, version := range []int{6, 7} {
|
|
payload := fmt.Sprintf(`{"mount_mode":"webdav","agent_version":%d}`, version)
|
|
req, err := http.NewRequest(http.MethodPost, fmt.Sprintf("http://127.0.0.1:%d/v1/status", port), strings.NewReader(payload))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
req.Header.Set("Authorization", "Bearer "+token)
|
|
res, err := http.DefaultClient.Do(req)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
res.Body.Close()
|
|
if res.StatusCode != http.StatusOK {
|
|
t.Fatalf("agent status: %s", res.Status)
|
|
}
|
|
stats, err := a.GetVMStats("", name)
|
|
if err != nil || !stats.GuestToolsConnected || stats.GuestToolsAgentVersion != version {
|
|
t.Fatalf("VM stats: %+v, %v", stats, err)
|
|
}
|
|
encoded, err := json.Marshal(stats)
|
|
if err != nil || !strings.Contains(string(encoded), fmt.Sprintf(`"guest_tools_agent_version":%d`, version)) {
|
|
t.Fatalf("VM stats JSON: %s, %v", encoded, err)
|
|
}
|
|
}
|
|
}
|