- WithService now calls factory, discovers service name from package path via
reflect/runtime (last path segment, _test suffix stripped, lowercased), and
calls RegisterService — which handles Startable/Stoppable/HandleIPCEvents
- If factory returns nil Value (self-registered), WithService returns OK without
a second registration
- Add contract_test.go with _Good/_Bad tests covering all three code paths
- Fix core.go Cli() accessor: use ServiceFor[*Cli](c, "cli") (was cli.New())
- Fix pre-existing })) → }}) syntax errors in command_test, service_test, lock_test
- Fix pre-existing Options{...} → NewOptions(...) in core_test, data_test,
drive_test, i18n_test (Options is a struct, not a slice)
Co-Authored-By: Virgil <virgil@lethean.io>
80 lines
2.3 KiB
Go
80 lines
2.3 KiB
Go
package core_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
. "dappco.re/go/core"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
// --- Drive (Transport Handles) ---
|
|
|
|
func TestDrive_New_Good(t *testing.T) {
|
|
c := New().Value.(*Core)
|
|
r := c.Drive().New(NewOptions(
|
|
Option{Key: "name", Value: "api"},
|
|
Option{Key: "transport", Value: "https://api.lthn.ai"},
|
|
))
|
|
assert.True(t, r.OK)
|
|
assert.Equal(t, "api", r.Value.(*DriveHandle).Name)
|
|
assert.Equal(t, "https://api.lthn.ai", r.Value.(*DriveHandle).Transport)
|
|
}
|
|
|
|
func TestDrive_New_Bad(t *testing.T) {
|
|
c := New().Value.(*Core)
|
|
// Missing name
|
|
r := c.Drive().New(NewOptions(
|
|
Option{Key: "transport", Value: "https://api.lthn.ai"},
|
|
))
|
|
assert.False(t, r.OK)
|
|
}
|
|
|
|
func TestDrive_Get_Good(t *testing.T) {
|
|
c := New().Value.(*Core)
|
|
c.Drive().New(NewOptions(
|
|
Option{Key: "name", Value: "ssh"},
|
|
Option{Key: "transport", Value: "ssh://claude@10.69.69.165"},
|
|
))
|
|
r := c.Drive().Get("ssh")
|
|
assert.True(t, r.OK)
|
|
handle := r.Value.(*DriveHandle)
|
|
assert.Equal(t, "ssh://claude@10.69.69.165", handle.Transport)
|
|
}
|
|
|
|
func TestDrive_Get_Bad(t *testing.T) {
|
|
c := New().Value.(*Core)
|
|
r := c.Drive().Get("nonexistent")
|
|
assert.False(t, r.OK)
|
|
}
|
|
|
|
func TestDrive_Has_Good(t *testing.T) {
|
|
c := New().Value.(*Core)
|
|
c.Drive().New(NewOptions(Option{Key: "name", Value: "mcp"}, Option{Key: "transport", Value: "mcp://mcp.lthn.sh"}))
|
|
assert.True(t, c.Drive().Has("mcp"))
|
|
assert.False(t, c.Drive().Has("missing"))
|
|
}
|
|
|
|
func TestDrive_Names_Good(t *testing.T) {
|
|
c := New().Value.(*Core)
|
|
c.Drive().New(NewOptions(Option{Key: "name", Value: "api"}, Option{Key: "transport", Value: "https://api.lthn.ai"}))
|
|
c.Drive().New(NewOptions(Option{Key: "name", Value: "ssh"}, Option{Key: "transport", Value: "ssh://claude@10.69.69.165"}))
|
|
c.Drive().New(NewOptions(Option{Key: "name", Value: "mcp"}, Option{Key: "transport", Value: "mcp://mcp.lthn.sh"}))
|
|
names := c.Drive().Names()
|
|
assert.Len(t, names, 3)
|
|
assert.Contains(t, names, "api")
|
|
assert.Contains(t, names, "ssh")
|
|
assert.Contains(t, names, "mcp")
|
|
}
|
|
|
|
func TestDrive_OptionsPreserved_Good(t *testing.T) {
|
|
c := New().Value.(*Core)
|
|
c.Drive().New(NewOptions(
|
|
Option{Key: "name", Value: "api"},
|
|
Option{Key: "transport", Value: "https://api.lthn.ai"},
|
|
Option{Key: "timeout", Value: 30},
|
|
))
|
|
r := c.Drive().Get("api")
|
|
assert.True(t, r.OK)
|
|
handle := r.Value.(*DriveHandle)
|
|
assert.Equal(t, 30, handle.Options.Int("timeout"))
|
|
}
|