mirror of
https://github.com/gogrlx/snack.git
synced 2026-04-02 05:08:42 -07:00
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)
46 lines
836 B
Go
46 lines
836 B
Go
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)
|
|
}
|