Files
mcp/internal/agent/testhelpers_test.go
Kyle Isom 08b3e2a472 Migrate module path from kyle/ to mc/ org
All import paths updated to git.wntrmute.dev/mc/. Bumps mcdsl to v1.2.0,
mc-proxy to v1.1.0.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 02:07:42 -07:00

66 lines
1.9 KiB
Go

package agent
import (
"context"
"log/slog"
"path/filepath"
"testing"
"git.wntrmute.dev/mc/mcp/internal/config"
"git.wntrmute.dev/mc/mcp/internal/registry"
"git.wntrmute.dev/mc/mcp/internal/runtime"
)
// fakeRuntime implements runtime.Runtime for testing.
type fakeRuntime struct {
containers []runtime.ContainerInfo
inspectMap map[string]runtime.ContainerInfo
listErr error
}
func (f *fakeRuntime) Pull(_ context.Context, _ string) error { return nil }
func (f *fakeRuntime) Run(_ context.Context, _ runtime.ContainerSpec) error { return nil }
func (f *fakeRuntime) Stop(_ context.Context, _ string) error { return nil }
func (f *fakeRuntime) Remove(_ context.Context, _ string) error { return nil }
func (f *fakeRuntime) Build(_ context.Context, _, _, _ string) error { return nil }
func (f *fakeRuntime) Push(_ context.Context, _ string) error { return nil }
func (f *fakeRuntime) ImageExists(_ context.Context, _ string) (bool, error) { return true, nil }
func (f *fakeRuntime) List(_ context.Context) ([]runtime.ContainerInfo, error) {
return f.containers, f.listErr
}
func (f *fakeRuntime) Inspect(_ context.Context, name string) (runtime.ContainerInfo, error) {
if f.inspectMap != nil {
if info, ok := f.inspectMap[name]; ok {
return info, nil
}
}
for _, c := range f.containers {
if c.Name == name {
return c, nil
}
}
return runtime.ContainerInfo{}, nil
}
// newTestAgent creates an Agent with a temp database for testing.
func newTestAgent(t *testing.T, rt runtime.Runtime) *Agent {
t.Helper()
db, err := registry.Open(filepath.Join(t.TempDir(), "test.db"))
if err != nil {
t.Fatalf("open test db: %v", err)
}
t.Cleanup(func() { _ = db.Close() })
return &Agent{
Config: &config.AgentConfig{
Agent: config.AgentSettings{NodeName: "test-node"},
},
DB: db,
Runtime: rt,
Logger: slog.Default(),
}
}