Move all tests from tests/ to package root for proper coverage.
Fix Fs zero-value: path() and validatePath() default empty root
to "/" so &Fs{} works without New().
New tests: PathGlob, PathIsAbs, CleanPath, Cli.SetOutput,
ServiceShutdown, Core.Context, Fs zero-value, Fs protected
delete, Command lifecycle with implementation, error formatting
branches, PerformAsync completion/no-handler/after-shutdown,
Extract with templates, Embed path traversal.
Coverage: 76.9% → 82.3% (23 test files).
Co-Authored-By: Virgil <virgil@lethean.io>
55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
package core_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
. "dappco.re/go/core"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestLock_Good(t *testing.T) {
|
|
c := New()
|
|
lock := c.Lock("test")
|
|
assert.NotNil(t, lock)
|
|
assert.NotNil(t, lock.Mutex)
|
|
}
|
|
|
|
func TestLock_SameName_Good(t *testing.T) {
|
|
c := New()
|
|
l1 := c.Lock("shared")
|
|
l2 := c.Lock("shared")
|
|
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 TestLockEnable_Good(t *testing.T) {
|
|
c := New()
|
|
c.Service("early", Service{})
|
|
c.LockEnable()
|
|
c.LockApply()
|
|
|
|
r := c.Service("late", Service{})
|
|
assert.False(t, r.OK)
|
|
}
|
|
|
|
func TestStartables_Good(t *testing.T) {
|
|
c := New()
|
|
c.Service("s", Service{OnStart: func() Result { return Result{OK: true} }})
|
|
r := c.Startables()
|
|
assert.True(t, r.OK)
|
|
assert.Len(t, r.Value.([]*Service), 1)
|
|
}
|
|
|
|
func TestStoppables_Good(t *testing.T) {
|
|
c := New()
|
|
c.Service("s", Service{OnStop: func() Result { return Result{OK: true} }})
|
|
r := c.Stoppables()
|
|
assert.True(t, r.OK)
|
|
assert.Len(t, r.Value.([]*Service), 1)
|
|
}
|