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>
76 lines
1.6 KiB
Go
76 lines
1.6 KiB
Go
package core_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
. "forge.lthn.ai/core/go/pkg/core"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
// --- Cli ---
|
|
|
|
func TestCli_Good(t *testing.T) {
|
|
c := New()
|
|
assert.NotNil(t, c.Cli())
|
|
assert.NotNil(t, c.Cli().Command())
|
|
}
|
|
|
|
func TestCli_Named_Good(t *testing.T) {
|
|
c := New(Options{{K: "name", V: "myapp"}})
|
|
assert.NotNil(t, c.Cli().Command())
|
|
}
|
|
|
|
func TestCli_NewChildCommand_Good(t *testing.T) {
|
|
c := New(Options{{K: "name", V: "myapp"}})
|
|
child := c.Cli().NewChildCommand("test", "a test command")
|
|
assert.NotNil(t, child)
|
|
}
|
|
|
|
func TestCli_AddCommand_Good(t *testing.T) {
|
|
c := New()
|
|
cmd := NewCommand("hello", "says hello")
|
|
c.Cli().AddCommand(cmd)
|
|
}
|
|
|
|
func TestCli_Flags_Good(t *testing.T) {
|
|
c := New()
|
|
var name string
|
|
var debug bool
|
|
var port int
|
|
c.Cli().StringFlag("name", "app name", &name)
|
|
c.Cli().BoolFlag("debug", "enable debug", &debug)
|
|
c.Cli().IntFlag("port", "port number", &port)
|
|
}
|
|
|
|
func TestCli_Run_Good(t *testing.T) {
|
|
c := New()
|
|
executed := false
|
|
c.Cli().Command().Action(func() error {
|
|
executed = true
|
|
return nil
|
|
})
|
|
err := c.Cli().Run("")
|
|
assert.NoError(t, err)
|
|
assert.True(t, executed)
|
|
}
|
|
|
|
// --- Command ---
|
|
|
|
func TestCommand_New_Good(t *testing.T) {
|
|
cmd := NewCommand("test", "a test command")
|
|
assert.NotNil(t, cmd)
|
|
}
|
|
|
|
func TestCommand_Child_Good(t *testing.T) {
|
|
parent := NewCommand("root")
|
|
child := parent.NewChildCommand("sub", "a subcommand")
|
|
assert.NotNil(t, child)
|
|
}
|
|
|
|
func TestCommand_Flags_Good(t *testing.T) {
|
|
cmd := NewCommand("test")
|
|
var name string
|
|
var debug bool
|
|
cmd.StringFlag("name", "app name", &name)
|
|
cmd.BoolFlag("debug", "enable debug", &debug)
|
|
}
|