New tests: Data List/ListNames/Extract, I18n with mock Translator, Fs full surface (EnsureDir, IsDir, IsFile, Exists, List, Stat, Open, Create, Append, ReadStream, WriteStream, Delete, DeleteAll, Rename), Log all levels + Security + Username + Default + LogErr + LogPan, Embed ScanAssets + GeneratePack + MountEmbed, Runtime ServiceName, Core LogError/LogWarn/Must helpers. Fixes: NewCommand inits flagset, New() wires Cli root command + app. Remaining 0% (excluding CLI/App): compress, getAllFiles (internal), Reports/appendReport (needs ErrorPanic filePath), SetOutput (trivial). Co-Authored-By: Virgil <virgil@lethean.io>
93 lines
1.9 KiB
Go
93 lines
1.9 KiB
Go
package core_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
. "forge.lthn.ai/core/go/pkg/core"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
// --- New ---
|
|
|
|
func TestNew_Good(t *testing.T) {
|
|
c := New()
|
|
assert.NotNil(t, c)
|
|
}
|
|
|
|
func TestNew_WithOptions_Good(t *testing.T) {
|
|
c := New(Options{{K: "name", V: "myapp"}})
|
|
assert.NotNil(t, c)
|
|
assert.Equal(t, "myapp", c.App().Name)
|
|
}
|
|
|
|
func TestNew_WithOptions_Bad(t *testing.T) {
|
|
// Empty options — should still create a valid Core
|
|
c := New(Options{})
|
|
assert.NotNil(t, c)
|
|
}
|
|
|
|
// --- Accessors ---
|
|
|
|
func TestAccessors_Good(t *testing.T) {
|
|
c := New()
|
|
assert.NotNil(t, c.App())
|
|
assert.NotNil(t, c.Data())
|
|
assert.NotNil(t, c.Drive())
|
|
assert.NotNil(t, c.Fs())
|
|
assert.NotNil(t, c.Config())
|
|
assert.NotNil(t, c.Error())
|
|
assert.NotNil(t, c.Log())
|
|
assert.NotNil(t, c.Cli())
|
|
assert.NotNil(t, c.IPC())
|
|
assert.NotNil(t, c.I18n())
|
|
assert.Equal(t, c, c.Core())
|
|
}
|
|
|
|
func TestOptions_Accessor_Good(t *testing.T) {
|
|
c := New(Options{
|
|
{K: "name", V: "testapp"},
|
|
{K: "port", V: 8080},
|
|
{K: "debug", V: true},
|
|
})
|
|
opts := c.Options()
|
|
assert.NotNil(t, opts)
|
|
assert.Equal(t, "testapp", opts.String("name"))
|
|
assert.Equal(t, 8080, opts.Int("port"))
|
|
assert.True(t, opts.Bool("debug"))
|
|
}
|
|
|
|
func TestOptions_Accessor_Nil(t *testing.T) {
|
|
c := New()
|
|
// No options passed — Options() returns nil
|
|
assert.Nil(t, c.Options())
|
|
}
|
|
|
|
// --- Core Error/Log Helpers ---
|
|
|
|
func TestCore_LogError_Good(t *testing.T) {
|
|
c := New()
|
|
cause := assert.AnError
|
|
err := c.LogError(cause, "test.Op", "something broke")
|
|
assert.Error(t, err)
|
|
assert.ErrorIs(t, err, cause)
|
|
}
|
|
|
|
func TestCore_LogWarn_Good(t *testing.T) {
|
|
c := New()
|
|
err := c.LogWarn(assert.AnError, "test.Op", "heads up")
|
|
assert.Error(t, err)
|
|
}
|
|
|
|
func TestCore_Must_Ugly(t *testing.T) {
|
|
c := New()
|
|
assert.Panics(t, func() {
|
|
c.Must(assert.AnError, "test.Op", "fatal")
|
|
})
|
|
}
|
|
|
|
func TestCore_Must_Nil_Good(t *testing.T) {
|
|
c := New()
|
|
assert.NotPanics(t, func() {
|
|
c.Must(nil, "test.Op", "no error")
|
|
})
|
|
}
|