go/tests/lock_test.go
Snider 1ca010e1fb test: rewrite test suite for AX primitives API
164 tests, 41.3% coverage. Tests written against the public API only
(external test package, no _test.go in pkg/core/).

Covers: New(Options), Data, Drive, Config, Service, Error, IPC,
Fs, Cli, Lock, Array, Log, App, Runtime, Task.

Fixes: NewCommand now inits flagset, New() wires Cli root command.

Old tests removed — they referenced With*, RegisterService, and
other patterns that no longer exist.

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 08:42:38 +00:00

69 lines
1.3 KiB
Go

package core_test
import (
"testing"
. "forge.lthn.ai/core/go/pkg/core"
"github.com/stretchr/testify/assert"
)
// --- Lock (Named Mutexes) ---
func TestLock_Good(t *testing.T) {
c := New()
lock := c.Lock("test")
assert.NotNil(t, lock)
assert.NotNil(t, lock.Mu)
}
func TestLock_SameName_Good(t *testing.T) {
c := New()
l1 := c.Lock("shared")
l2 := c.Lock("shared")
// Same name returns same lock
assert.Equal(t, l1, l2)
}
func TestLock_DifferentName_Good(t *testing.T) {
c := New()
l1 := c.Lock("a")
l2 := c.Lock("b")
assert.NotEqual(t, l1, l2)
}
func TestLock_MutexWorks_Good(t *testing.T) {
c := New()
lock := c.Lock("counter")
counter := 0
lock.Mu.Lock()
counter++
lock.Mu.Unlock()
assert.Equal(t, 1, counter)
}
func TestLockEnable_Good(t *testing.T) {
c := New()
c.Service("early", struct{}{})
c.LockEnable()
c.LockApply()
// After lock, registration should fail
result := c.Service("late", struct{}{})
assert.NotNil(t, result)
}
func TestStartables_Good(t *testing.T) {
c := New()
svc := &testService{name: "s"}
c.Service("s", svc)
startables := c.Startables()
assert.Len(t, startables, 1)
}
func TestStoppables_Good(t *testing.T) {
c := New()
svc := &testService{name: "s"}
c.Service("s", svc)
stoppables := c.Stoppables()
assert.Len(t, stoppables, 1)
}