* test(windows): resolve the home dir via USERPROFILE TestGetClaudePluginVersion and two TestDetectBootstrapAction_* cases override HOME to point discovery at a temp dir, but the code resolves the home dir with os.UserHomeDir(), which reads USERPROFILE on Windows and HOME elsewhere. Set both so the tests are hermetic on every platform. Agent-Signature: claude-code-opus-4.8-high on behalf of Marco Del Pin * test(windows): use platform-absolute paths in fixtures Two tests assert behavior gated on filepath.IsAbs but used the POSIX literals "/absolute/path" / "/var/run/dolt.sock", which filepath.IsAbs reports as NOT absolute on Windows (no volume) -- so the assertions were silent no-ops there. Derive platform-absolute paths (t.TempDir()) instead. Affects TestContextInfo_SaveStripAbsoluteDataDir and TestNewDatabaseServer_BackendExternal. Agent-Signature: claude-code-opus-4.8-high on behalf of Marco Del Pin * test: skip embedded hook-firing test on Windows (GH#3800) The test writes an extensionless #!/bin/sh hook, which Windows CreateProcess cannot execute (no shebang dispatch), so no payload is ever logged and the assertions fail. Guard it with the same runtime.GOOS == "windows" skip already used for this class in internal/hooks/hooks_test.go (GH#3800). Agent-Signature: claude-code-opus-4.8-high on behalf of Marco Del Pin * test: skip branch-tracking pull test when the dolt CLI is absent TestPullWithAutoResolve_BranchTrackingFallbackSuccess builds its file:// remote with the dolt CLI, so it hard-fails with "exec: dolt: executable file not found" on hosts without the binary. Guard it with exec.LookPath, matching the existing guards in this package (bootstrap_test.go, fsck_test.go). The store under test speaks the MySQL protocol and needs no local dolt binary. Agent-Signature: claude-code-opus-4.8-high on behalf of Marco Del Pin
96 lines
2.8 KiB
Go
96 lines
2.8 KiB
Go
package main
|
|
|
|
import (
|
|
"path/filepath"
|
|
"runtime"
|
|
"testing"
|
|
|
|
"github.com/steveyegge/beads/internal/configfile"
|
|
"github.com/steveyegge/beads/internal/storage/dbproxy/proxy"
|
|
"github.com/steveyegge/beads/internal/storage/dbproxy/server"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestNewDatabaseServer_BackendExternal(t *testing.T) {
|
|
t.Run("valid tcp config builds an ExternalDoltServer", func(t *testing.T) {
|
|
srv, err := newDatabaseServer(
|
|
proxy.BackendExternal,
|
|
"", "", "", "", "",
|
|
configfile.ExternalDoltConfig{Host: "db.internal", Port: 3306},
|
|
)
|
|
require.NoError(t, err)
|
|
require.NotNil(t, srv)
|
|
_, ok := srv.(*server.ExternalDoltServer)
|
|
assert.True(t, ok, "expected *server.ExternalDoltServer, got %T", srv)
|
|
})
|
|
|
|
t.Run("invalid config bubbles validation error", func(t *testing.T) {
|
|
_, err := newDatabaseServer(
|
|
proxy.BackendExternal,
|
|
"", "", "", "", "",
|
|
configfile.ExternalDoltConfig{},
|
|
)
|
|
require.Error(t, err)
|
|
assert.Contains(t, err.Error(), "ExternalDoltConfig")
|
|
})
|
|
|
|
t.Run("unix socket config builds an ExternalDoltServer", func(t *testing.T) {
|
|
// ExternalDoltConfig.Validate() requires an absolute Socket via filepath.IsAbs,
|
|
// which is platform-dependent: /var/run/dolt.sock is NOT absolute on Windows
|
|
// (no volume). Use a platform-absolute socket path so the same construction
|
|
// path is exercised everywhere.
|
|
socket := "/var/run/dolt.sock"
|
|
if runtime.GOOS == "windows" {
|
|
socket = filepath.Join(t.TempDir(), "dolt.sock")
|
|
}
|
|
srv, err := newDatabaseServer(
|
|
proxy.BackendExternal,
|
|
"", "", "", "", "",
|
|
configfile.ExternalDoltConfig{Socket: socket},
|
|
)
|
|
require.NoError(t, err)
|
|
require.NotNil(t, srv)
|
|
_, ok := srv.(*server.ExternalDoltServer)
|
|
assert.True(t, ok)
|
|
})
|
|
}
|
|
|
|
func TestNewDatabaseServer_BackendLocalSharedServerStillStubbed(t *testing.T) {
|
|
_, err := newDatabaseServer(
|
|
proxy.BackendLocalSharedServer,
|
|
"/tmp/root", "/tmp/cfg", "/tmp/log", "/usr/bin/dolt", "",
|
|
configfile.ExternalDoltConfig{},
|
|
)
|
|
require.Error(t, err)
|
|
assert.Contains(t, err.Error(), "not yet implemented")
|
|
}
|
|
|
|
func TestNewDatabaseServer_UnknownBackendRejected(t *testing.T) {
|
|
_, err := newDatabaseServer(
|
|
proxy.Backend("bogus"),
|
|
"", "", "", "", "",
|
|
configfile.ExternalDoltConfig{},
|
|
)
|
|
require.Error(t, err)
|
|
assert.Contains(t, err.Error(), "unknown backend")
|
|
}
|
|
|
|
func TestDbProxyChildRegistersExternalFlags(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
defaultText string
|
|
}{
|
|
{"external-host", ""},
|
|
{"external-port", "0"},
|
|
{"external-socket-path", ""},
|
|
{"external-keep-alive", "0s"},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
f := dbProxyChildCmd.Flags().Lookup(tc.name)
|
|
require.NotNil(t, f, "db-proxy-child does not register --%s", tc.name)
|
|
assert.Equal(t, tc.defaultText, f.DefValue, "--%s default", tc.name)
|
|
})
|
|
}
|
|
}
|