go/pkg/coredeno/lifecycle_test.go
Claude 93be6c5ed2
feat(coredeno): sidecar Start/Stop/IsRunning lifecycle
Process launch with context cancellation, socket directory auto-creation,
channel-based stop synchronization. Uses sleep as fake Deno in tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 21:02:37 +00:00

56 lines
1.2 KiB
Go

package coredeno
import (
"context"
"os"
"path/filepath"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestStart_Good(t *testing.T) {
sockDir := t.TempDir()
sc := NewSidecar(Options{
DenoPath: "sleep",
SocketPath: filepath.Join(sockDir, "test.sock"),
})
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
err := sc.Start(ctx, "10") // sleep 10 — will be killed by Stop
require.NoError(t, err)
assert.True(t, sc.IsRunning())
err = sc.Stop()
require.NoError(t, err)
assert.False(t, sc.IsRunning())
}
func TestStop_Good_NotStarted(t *testing.T) {
sc := NewSidecar(Options{DenoPath: "sleep"})
err := sc.Stop()
assert.NoError(t, err, "stopping a not-started sidecar should be a no-op")
}
func TestSocketDirCreated_Good(t *testing.T) {
dir := t.TempDir()
sockPath := filepath.Join(dir, "sub", "deno.sock")
sc := NewSidecar(Options{
DenoPath: "sleep",
SocketPath: sockPath,
})
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
err := sc.Start(ctx, "10")
require.NoError(t, err)
defer sc.Stop()
_, err = os.Stat(filepath.Join(dir, "sub"))
assert.NoError(t, err, "socket directory should be created")
}