fix(detect): wire up ports package for OpenBSD detection

The ports package was fully implemented but detect_openbsd.go still
returned nil candidates with a stale TODO. Wire up ports.New() so
OpenBSD systems can auto-detect their package manager.

Also adds:
- Unit tests for GetCapabilities with mock managers (base + full)
- Unit tests for Locker mutual exclusion
- Edge case tests for ports parser (empty input, whitespace, fallback)
- Minor dep updates (charmbracelet/ultraviolet, charmbracelet/x)
This commit is contained in:
2026-03-05 09:03:38 +00:00
parent 397e865107
commit 90ca983200
6 changed files with 228 additions and 9 deletions

45
mutex_test.go Normal file
View File

@@ -0,0 +1,45 @@
package snack_test
import (
"sync"
"sync/atomic"
"testing"
"github.com/gogrlx/snack"
"github.com/stretchr/testify/assert"
)
func TestLocker_MutualExclusion(t *testing.T) {
var l snack.Locker
var counter int64
var wg sync.WaitGroup
const goroutines = 50
wg.Add(goroutines)
for range goroutines {
go func() {
defer wg.Done()
l.Lock()
defer l.Unlock()
// If the lock works, only one goroutine touches
// the counter at a time.
cur := atomic.LoadInt64(&counter)
atomic.StoreInt64(&counter, cur+1)
}()
}
wg.Wait()
assert.Equal(t, int64(goroutines), atomic.LoadInt64(&counter))
}
func TestLocker_LockUnlock(t *testing.T) {
var l snack.Locker
var n int
// Should not deadlock; verifies lock/unlock cycle works twice.
l.Lock()
n++
l.Unlock()
l.Lock()
n++
l.Unlock()
assert.Equal(t, 2, n)
}