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
|
|
|
package core_test
|
|
|
|
|
|
|
|
|
|
import (
|
feat: inline tests + Fs zero-value fix + coverage 76.9% → 82.3%
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>
2026-03-22 13:30:01 +00:00
|
|
|
"bytes"
|
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
|
|
|
"testing"
|
|
|
|
|
|
2026-03-20 21:00:48 +00:00
|
|
|
. "dappco.re/go/core"
|
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
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
2026-03-20 12:08:19 +00:00
|
|
|
// --- Cli Surface ---
|
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
|
|
|
|
|
|
|
|
func TestCli_Good(t *testing.T) {
|
2026-03-24 16:23:33 +00:00
|
|
|
c := New().Value.(*Core)
|
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
|
|
|
assert.NotNil(t, c.Cli())
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-20 12:08:19 +00:00
|
|
|
func TestCli_Banner_Good(t *testing.T) {
|
2026-03-24 19:17:12 +00:00
|
|
|
c := New(WithOptions(NewOptions(Option{Key: "name", Value: "myapp"}))).Value.(*Core)
|
2026-03-20 12:08:19 +00:00
|
|
|
assert.Equal(t, "myapp", c.Cli().Banner())
|
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
|
|
|
}
|
|
|
|
|
|
2026-03-20 12:08:19 +00:00
|
|
|
func TestCli_SetBanner_Good(t *testing.T) {
|
2026-03-24 16:23:33 +00:00
|
|
|
c := New().Value.(*Core)
|
2026-03-20 12:08:19 +00:00
|
|
|
c.Cli().SetBanner(func(_ *Cli) string { return "Custom Banner" })
|
|
|
|
|
assert.Equal(t, "Custom Banner", c.Cli().Banner())
|
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
|
|
|
}
|
|
|
|
|
|
2026-03-20 12:08:19 +00:00
|
|
|
func TestCli_Run_Good(t *testing.T) {
|
2026-03-24 16:23:33 +00:00
|
|
|
c := New().Value.(*Core)
|
2026-03-20 12:08:19 +00:00
|
|
|
executed := false
|
2026-03-20 14:44:29 +00:00
|
|
|
c.Command("hello", Command{Action: func(_ Options) Result {
|
2026-03-20 12:08:19 +00:00
|
|
|
executed = true
|
2026-03-20 13:30:22 +00:00
|
|
|
return Result{Value: "world", OK: true}
|
2026-03-24 19:17:12 +00:00
|
|
|
}))
|
2026-03-20 12:08:19 +00:00
|
|
|
r := c.Cli().Run("hello")
|
|
|
|
|
assert.True(t, r.OK)
|
|
|
|
|
assert.Equal(t, "world", r.Value)
|
|
|
|
|
assert.True(t, executed)
|
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
|
|
|
}
|
|
|
|
|
|
2026-03-20 12:08:19 +00:00
|
|
|
func TestCli_Run_Nested_Good(t *testing.T) {
|
2026-03-24 16:23:33 +00:00
|
|
|
c := New().Value.(*Core)
|
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
|
|
|
executed := false
|
2026-03-20 14:44:29 +00:00
|
|
|
c.Command("deploy/to/homelab", Command{Action: func(_ Options) Result {
|
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
|
|
|
executed = true
|
2026-03-20 13:30:22 +00:00
|
|
|
return Result{OK: true}
|
2026-03-24 19:17:12 +00:00
|
|
|
}))
|
2026-03-20 12:08:19 +00:00
|
|
|
r := c.Cli().Run("deploy", "to", "homelab")
|
|
|
|
|
assert.True(t, r.OK)
|
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
|
|
|
assert.True(t, executed)
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-20 12:08:19 +00:00
|
|
|
func TestCli_Run_WithFlags_Good(t *testing.T) {
|
2026-03-24 16:23:33 +00:00
|
|
|
c := New().Value.(*Core)
|
2026-03-20 12:08:19 +00:00
|
|
|
var received Options
|
2026-03-20 14:44:29 +00:00
|
|
|
c.Command("serve", Command{Action: func(opts Options) Result {
|
2026-03-20 12:08:19 +00:00
|
|
|
received = opts
|
2026-03-20 13:30:22 +00:00
|
|
|
return Result{OK: true}
|
2026-03-24 19:17:12 +00:00
|
|
|
}))
|
2026-03-20 12:08:19 +00:00
|
|
|
c.Cli().Run("serve", "--port=8080", "--debug")
|
|
|
|
|
assert.Equal(t, "8080", received.String("port"))
|
|
|
|
|
assert.True(t, received.Bool("debug"))
|
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
|
|
|
}
|
|
|
|
|
|
2026-03-20 12:08:19 +00:00
|
|
|
func TestCli_Run_NoCommand_Good(t *testing.T) {
|
2026-03-24 16:23:33 +00:00
|
|
|
c := New().Value.(*Core)
|
2026-03-20 12:08:19 +00:00
|
|
|
r := c.Cli().Run()
|
|
|
|
|
assert.False(t, r.OK)
|
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
|
|
|
}
|
|
|
|
|
|
2026-03-20 12:08:19 +00:00
|
|
|
func TestCli_PrintHelp_Good(t *testing.T) {
|
2026-03-24 19:17:12 +00:00
|
|
|
c := New(WithOptions(NewOptions(Option{Key: "name", Value: "myapp"}))).Value.(*Core)
|
|
|
|
|
c.Command("deploy", Command{Action: func(_ Options) Result { return Result{OK: true} }))
|
|
|
|
|
c.Command("serve", Command{Action: func(_ Options) Result { return Result{OK: true} }))
|
2026-03-20 12:08:19 +00:00
|
|
|
c.Cli().PrintHelp()
|
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
|
|
|
}
|
feat: inline tests + Fs zero-value fix + coverage 76.9% → 82.3%
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>
2026-03-22 13:30:01 +00:00
|
|
|
|
|
|
|
|
func TestCli_SetOutput_Good(t *testing.T) {
|
2026-03-24 16:23:33 +00:00
|
|
|
c := New().Value.(*Core)
|
feat: inline tests + Fs zero-value fix + coverage 76.9% → 82.3%
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>
2026-03-22 13:30:01 +00:00
|
|
|
var buf bytes.Buffer
|
|
|
|
|
c.Cli().SetOutput(&buf)
|
|
|
|
|
c.Cli().Print("hello %s", "world")
|
|
|
|
|
assert.Contains(t, buf.String(), "hello world")
|
|
|
|
|
}
|