80 lines
2.2 KiB
Go
80 lines
2.2 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()
|
|
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()
|
|
// 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()
|
|
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()
|
|
r := c.Drive().Get("nonexistent")
|
|
assert.False(t, r.OK)
|
|
}
|
|
|
|
func TestDrive_Has_Good(t *testing.T) {
|
|
c := New()
|
|
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()
|
|
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()
|
|
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"))
|
|
}
|