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 (
|
|
|
|
|
"bytes"
|
|
|
|
|
"compress/gzip"
|
|
|
|
|
"encoding/base64"
|
|
|
|
|
"os"
|
|
|
|
|
"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"
|
|
|
|
|
)
|
|
|
|
|
|
feat: embed.go and data.go return Result throughout
Mount, MountEmbed, Open, ReadFile, ReadString, Sub, GetAsset,
GetAssetBytes, ScanAssets, GeneratePack, Extract → all return Result.
Data.ReadFile, ReadString, List, ListNames, Extract → Result.
Data.New uses Mount's Result internally.
Internal helpers (WalkDir callback, copyFile) stay error — they're
not public API.
231 tests, 77.4% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 14:13:47 +00:00
|
|
|
// --- Mount ---
|
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-24 23:26:43 +00:00
|
|
|
func mustMountTestFS(t *testing.T, basedir string) *Embed {
|
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
|
|
r := Mount(testFS, basedir)
|
|
|
|
|
assert.True(t, r.OK)
|
|
|
|
|
return r.Value.(*Embed)
|
|
|
|
|
}
|
|
|
|
|
|
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 TestMount_Good(t *testing.T) {
|
feat: embed.go and data.go return Result throughout
Mount, MountEmbed, Open, ReadFile, ReadString, Sub, GetAsset,
GetAssetBytes, ScanAssets, GeneratePack, Extract → all return Result.
Data.ReadFile, ReadString, List, ListNames, Extract → Result.
Data.New uses Mount's Result internally.
Internal helpers (WalkDir callback, copyFile) stay error — they're
not public API.
231 tests, 77.4% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 14:13:47 +00:00
|
|
|
r := Mount(testFS, "testdata")
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestMount_Bad(t *testing.T) {
|
feat: embed.go and data.go return Result throughout
Mount, MountEmbed, Open, ReadFile, ReadString, Sub, GetAsset,
GetAssetBytes, ScanAssets, GeneratePack, Extract → all return Result.
Data.ReadFile, ReadString, List, ListNames, Extract → Result.
Data.New uses Mount's Result internally.
Internal helpers (WalkDir callback, copyFile) stay error — they're
not public API.
231 tests, 77.4% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 14:13:47 +00:00
|
|
|
r := Mount(testFS, "nonexistent")
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
feat: embed.go and data.go return Result throughout
Mount, MountEmbed, Open, ReadFile, ReadString, Sub, GetAsset,
GetAssetBytes, ScanAssets, GeneratePack, Extract → all return Result.
Data.ReadFile, ReadString, List, ListNames, Extract → Result.
Data.New uses Mount's Result internally.
Internal helpers (WalkDir callback, copyFile) stay error — they're
not public API.
231 tests, 77.4% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 14:13:47 +00:00
|
|
|
// --- Embed methods ---
|
|
|
|
|
|
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 TestEmbed_ReadFile_Good(t *testing.T) {
|
2026-03-24 23:26:43 +00:00
|
|
|
emb := mustMountTestFS(t, "testdata")
|
feat: embed.go and data.go return Result throughout
Mount, MountEmbed, Open, ReadFile, ReadString, Sub, GetAsset,
GetAssetBytes, ScanAssets, GeneratePack, Extract → all return Result.
Data.ReadFile, ReadString, List, ListNames, Extract → Result.
Data.New uses Mount's Result internally.
Internal helpers (WalkDir callback, copyFile) stay error — they're
not public API.
231 tests, 77.4% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 14:13:47 +00:00
|
|
|
r := emb.ReadFile("test.txt")
|
|
|
|
|
assert.True(t, r.OK)
|
|
|
|
|
assert.Equal(t, "hello from testdata\n", string(r.Value.([]byte)))
|
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 TestEmbed_ReadString_Good(t *testing.T) {
|
2026-03-24 23:26:43 +00:00
|
|
|
emb := mustMountTestFS(t, "testdata")
|
feat: embed.go and data.go return Result throughout
Mount, MountEmbed, Open, ReadFile, ReadString, Sub, GetAsset,
GetAssetBytes, ScanAssets, GeneratePack, Extract → all return Result.
Data.ReadFile, ReadString, List, ListNames, Extract → Result.
Data.New uses Mount's Result internally.
Internal helpers (WalkDir callback, copyFile) stay error — they're
not public API.
231 tests, 77.4% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 14:13:47 +00:00
|
|
|
r := emb.ReadString("test.txt")
|
|
|
|
|
assert.True(t, r.OK)
|
|
|
|
|
assert.Equal(t, "hello from testdata\n", r.Value.(string))
|
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 TestEmbed_Open_Good(t *testing.T) {
|
2026-03-24 23:26:43 +00:00
|
|
|
emb := mustMountTestFS(t, "testdata")
|
feat: embed.go and data.go return Result throughout
Mount, MountEmbed, Open, ReadFile, ReadString, Sub, GetAsset,
GetAssetBytes, ScanAssets, GeneratePack, Extract → all return Result.
Data.ReadFile, ReadString, List, ListNames, Extract → Result.
Data.New uses Mount's Result internally.
Internal helpers (WalkDir callback, copyFile) stay error — they're
not public API.
231 tests, 77.4% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 14:13:47 +00:00
|
|
|
r := emb.Open("test.txt")
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestEmbed_ReadDir_Good(t *testing.T) {
|
2026-03-24 23:26:43 +00:00
|
|
|
emb := mustMountTestFS(t, "testdata")
|
fix: AX audit round 5 — full naming, Result returns throughout
Renames (via GoLand refactor):
- Option.K → Key, Option.V → Value
- Err.Op → Operation, Err.Msg → Message, Err.Err → Error
- CrashSystem.OS → OperatingSystem, Arch → Architecture
- TaskID → TaskIdentifier, TaskWithID → TaskWithIdentifier
- Ipc → IPC, BaseDir → BaseDirectory
- ServiceRuntime.Opts → Options
Return type changes:
- Options.Get, Config.Get → Result (was (any, bool))
- Embed.ReadDir → Result (was ([]fs.DirEntry, error))
- Translator.Translate, I18n.Translate → Result (was string)
Rule 6:
- data.go: propagate opts.Get failure, typed error for bad fs.FS
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 16:32:43 +00:00
|
|
|
r := emb.ReadDir(".")
|
|
|
|
|
assert.True(t, r.OK)
|
|
|
|
|
assert.NotEmpty(t, r.Value)
|
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 TestEmbed_Sub_Good(t *testing.T) {
|
2026-03-24 23:26:43 +00:00
|
|
|
emb := mustMountTestFS(t, ".")
|
feat: embed.go and data.go return Result throughout
Mount, MountEmbed, Open, ReadFile, ReadString, Sub, GetAsset,
GetAssetBytes, ScanAssets, GeneratePack, Extract → all return Result.
Data.ReadFile, ReadString, List, ListNames, Extract → Result.
Data.New uses Mount's Result internally.
Internal helpers (WalkDir callback, copyFile) stay error — they're
not public API.
231 tests, 77.4% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 14:13:47 +00:00
|
|
|
r := emb.Sub("testdata")
|
|
|
|
|
assert.True(t, r.OK)
|
|
|
|
|
sub := r.Value.(*Embed)
|
|
|
|
|
r2 := sub.ReadFile("test.txt")
|
|
|
|
|
assert.True(t, r2.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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestEmbed_BaseDir_Good(t *testing.T) {
|
2026-03-24 23:26:43 +00:00
|
|
|
emb := mustMountTestFS(t, "testdata")
|
2026-03-20 16:46:39 +00:00
|
|
|
assert.Equal(t, "testdata", emb.BaseDirectory())
|
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 TestEmbed_FS_Good(t *testing.T) {
|
2026-03-24 23:26:43 +00:00
|
|
|
emb := mustMountTestFS(t, "testdata")
|
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, emb.FS())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestEmbed_EmbedFS_Good(t *testing.T) {
|
2026-03-24 23:26:43 +00:00
|
|
|
emb := mustMountTestFS(t, "testdata")
|
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
|
|
|
efs := emb.EmbedFS()
|
|
|
|
|
_, err := efs.ReadFile("testdata/test.txt")
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
}
|
|
|
|
|
|
feat: embed.go and data.go return Result throughout
Mount, MountEmbed, Open, ReadFile, ReadString, Sub, GetAsset,
GetAssetBytes, ScanAssets, GeneratePack, Extract → all return Result.
Data.ReadFile, ReadString, List, ListNames, Extract → Result.
Data.New uses Mount's Result internally.
Internal helpers (WalkDir callback, copyFile) stay error — they're
not public API.
231 tests, 77.4% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 14:13:47 +00:00
|
|
|
// --- Extract ---
|
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 TestExtract_Good(t *testing.T) {
|
|
|
|
|
dir := t.TempDir()
|
feat: embed.go and data.go return Result throughout
Mount, MountEmbed, Open, ReadFile, ReadString, Sub, GetAsset,
GetAssetBytes, ScanAssets, GeneratePack, Extract → all return Result.
Data.ReadFile, ReadString, List, ListNames, Extract → Result.
Data.New uses Mount's Result internally.
Internal helpers (WalkDir callback, copyFile) stay error — they're
not public API.
231 tests, 77.4% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 14:13:47 +00:00
|
|
|
r := Extract(testFS, dir, nil)
|
|
|
|
|
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
|
|
|
|
feat: embed.go and data.go return Result throughout
Mount, MountEmbed, Open, ReadFile, ReadString, Sub, GetAsset,
GetAssetBytes, ScanAssets, GeneratePack, Extract → all return Result.
Data.ReadFile, ReadString, List, ListNames, Extract → Result.
Data.New uses Mount's Result internally.
Internal helpers (WalkDir callback, copyFile) stay error — they're
not public API.
231 tests, 77.4% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 14:13:47 +00:00
|
|
|
content, err := os.ReadFile(dir + "/testdata/test.txt")
|
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.NoError(t, err)
|
|
|
|
|
assert.Equal(t, "hello from testdata\n", string(content))
|
|
|
|
|
}
|
|
|
|
|
|
feat: embed.go and data.go return Result throughout
Mount, MountEmbed, Open, ReadFile, ReadString, Sub, GetAsset,
GetAssetBytes, ScanAssets, GeneratePack, Extract → all return Result.
Data.ReadFile, ReadString, List, ListNames, Extract → Result.
Data.New uses Mount's Result internally.
Internal helpers (WalkDir callback, copyFile) stay error — they're
not public API.
231 tests, 77.4% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 14:13:47 +00:00
|
|
|
// --- Asset Pack ---
|
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 TestAddGetAsset_Good(t *testing.T) {
|
|
|
|
|
AddAsset("test-group", "greeting", mustCompress("hello world"))
|
feat: embed.go and data.go return Result throughout
Mount, MountEmbed, Open, ReadFile, ReadString, Sub, GetAsset,
GetAssetBytes, ScanAssets, GeneratePack, Extract → all return Result.
Data.ReadFile, ReadString, List, ListNames, Extract → Result.
Data.New uses Mount's Result internally.
Internal helpers (WalkDir callback, copyFile) stay error — they're
not public API.
231 tests, 77.4% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 14:13:47 +00:00
|
|
|
r := GetAsset("test-group", "greeting")
|
|
|
|
|
assert.True(t, r.OK)
|
|
|
|
|
assert.Equal(t, "hello world", r.Value.(string))
|
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 TestGetAsset_Bad(t *testing.T) {
|
feat: embed.go and data.go return Result throughout
Mount, MountEmbed, Open, ReadFile, ReadString, Sub, GetAsset,
GetAssetBytes, ScanAssets, GeneratePack, Extract → all return Result.
Data.ReadFile, ReadString, List, ListNames, Extract → Result.
Data.New uses Mount's Result internally.
Internal helpers (WalkDir callback, copyFile) stay error — they're
not public API.
231 tests, 77.4% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 14:13:47 +00:00
|
|
|
r := GetAsset("missing-group", "missing")
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestGetAssetBytes_Good(t *testing.T) {
|
|
|
|
|
AddAsset("bytes-group", "file", mustCompress("binary content"))
|
feat: embed.go and data.go return Result throughout
Mount, MountEmbed, Open, ReadFile, ReadString, Sub, GetAsset,
GetAssetBytes, ScanAssets, GeneratePack, Extract → all return Result.
Data.ReadFile, ReadString, List, ListNames, Extract → Result.
Data.New uses Mount's Result internally.
Internal helpers (WalkDir callback, copyFile) stay error — they're
not public API.
231 tests, 77.4% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 14:13:47 +00:00
|
|
|
r := GetAssetBytes("bytes-group", "file")
|
|
|
|
|
assert.True(t, r.OK)
|
|
|
|
|
assert.Equal(t, []byte("binary content"), r.Value.([]byte))
|
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: embed.go and data.go return Result throughout
Mount, MountEmbed, Open, ReadFile, ReadString, Sub, GetAsset,
GetAssetBytes, ScanAssets, GeneratePack, Extract → all return Result.
Data.ReadFile, ReadString, List, ListNames, Extract → Result.
Data.New uses Mount's Result internally.
Internal helpers (WalkDir callback, copyFile) stay error — they're
not public API.
231 tests, 77.4% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 14:13:47 +00:00
|
|
|
func TestMountEmbed_Good(t *testing.T) {
|
|
|
|
|
r := MountEmbed(testFS, "testdata")
|
|
|
|
|
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
|
|
|
}
|
test: 200 tests, 50.2% coverage — Data, I18n, Fs, Log, Embed, Runtime
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>
2026-03-20 10:49:33 +00:00
|
|
|
|
feat: embed.go and data.go return Result throughout
Mount, MountEmbed, Open, ReadFile, ReadString, Sub, GetAsset,
GetAssetBytes, ScanAssets, GeneratePack, Extract → all return Result.
Data.ReadFile, ReadString, List, ListNames, Extract → Result.
Data.New uses Mount's Result internally.
Internal helpers (WalkDir callback, copyFile) stay error — they're
not public API.
231 tests, 77.4% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 14:13:47 +00:00
|
|
|
// --- ScanAssets ---
|
test: 200 tests, 50.2% coverage — Data, I18n, Fs, Log, Embed, Runtime
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>
2026-03-20 10:49:33 +00:00
|
|
|
|
|
|
|
|
func TestScanAssets_Good(t *testing.T) {
|
feat: embed.go and data.go return Result throughout
Mount, MountEmbed, Open, ReadFile, ReadString, Sub, GetAsset,
GetAssetBytes, ScanAssets, GeneratePack, Extract → all return Result.
Data.ReadFile, ReadString, List, ListNames, Extract → Result.
Data.New uses Mount's Result internally.
Internal helpers (WalkDir callback, copyFile) stay error — they're
not public API.
231 tests, 77.4% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 14:13:47 +00:00
|
|
|
r := ScanAssets([]string{"testdata/scantest/sample.go"})
|
|
|
|
|
assert.True(t, r.OK)
|
|
|
|
|
pkgs := r.Value.([]ScannedPackage)
|
test: 200 tests, 50.2% coverage — Data, I18n, Fs, Log, Embed, Runtime
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>
2026-03-20 10:49:33 +00:00
|
|
|
assert.Len(t, pkgs, 1)
|
|
|
|
|
assert.Equal(t, "scantest", pkgs[0].PackageName)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestScanAssets_Bad(t *testing.T) {
|
feat: embed.go and data.go return Result throughout
Mount, MountEmbed, Open, ReadFile, ReadString, Sub, GetAsset,
GetAssetBytes, ScanAssets, GeneratePack, Extract → all return Result.
Data.ReadFile, ReadString, List, ListNames, Extract → Result.
Data.New uses Mount's Result internally.
Internal helpers (WalkDir callback, copyFile) stay error — they're
not public API.
231 tests, 77.4% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 14:13:47 +00:00
|
|
|
r := ScanAssets([]string{"nonexistent.go"})
|
|
|
|
|
assert.False(t, r.OK)
|
test: 200 tests, 50.2% coverage — Data, I18n, Fs, Log, Embed, Runtime
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>
2026-03-20 10:49:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestGeneratePack_Empty_Good(t *testing.T) {
|
|
|
|
|
pkg := ScannedPackage{PackageName: "empty"}
|
feat: embed.go and data.go return Result throughout
Mount, MountEmbed, Open, ReadFile, ReadString, Sub, GetAsset,
GetAssetBytes, ScanAssets, GeneratePack, Extract → all return Result.
Data.ReadFile, ReadString, List, ListNames, Extract → Result.
Data.New uses Mount's Result internally.
Internal helpers (WalkDir callback, copyFile) stay error — they're
not public API.
231 tests, 77.4% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 14:13:47 +00:00
|
|
|
r := GeneratePack(pkg)
|
|
|
|
|
assert.True(t, r.OK)
|
|
|
|
|
assert.Contains(t, r.Value.(string), "package empty")
|
test: 200 tests, 50.2% coverage — Data, I18n, Fs, Log, Embed, Runtime
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>
2026-03-20 10:49:33 +00:00
|
|
|
}
|
2026-03-20 12:10:41 +00:00
|
|
|
|
|
|
|
|
func TestGeneratePack_WithFiles_Good(t *testing.T) {
|
|
|
|
|
dir := t.TempDir()
|
|
|
|
|
assetDir := dir + "/mygroup"
|
|
|
|
|
os.MkdirAll(assetDir, 0755)
|
|
|
|
|
os.WriteFile(assetDir+"/hello.txt", []byte("hello world"), 0644)
|
|
|
|
|
|
2026-03-20 21:00:48 +00:00
|
|
|
source := "package test\nimport \"dappco.re/go/core\"\nfunc example() {\n\t_, _ = core.GetAsset(\"mygroup\", \"hello.txt\")\n}\n"
|
2026-03-20 12:10:41 +00:00
|
|
|
goFile := dir + "/test.go"
|
|
|
|
|
os.WriteFile(goFile, []byte(source), 0644)
|
|
|
|
|
|
feat: embed.go and data.go return Result throughout
Mount, MountEmbed, Open, ReadFile, ReadString, Sub, GetAsset,
GetAssetBytes, ScanAssets, GeneratePack, Extract → all return Result.
Data.ReadFile, ReadString, List, ListNames, Extract → Result.
Data.New uses Mount's Result internally.
Internal helpers (WalkDir callback, copyFile) stay error — they're
not public API.
231 tests, 77.4% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 14:13:47 +00:00
|
|
|
sr := ScanAssets([]string{goFile})
|
|
|
|
|
assert.True(t, sr.OK)
|
|
|
|
|
pkgs := sr.Value.([]ScannedPackage)
|
2026-03-20 12:10:41 +00:00
|
|
|
|
feat: embed.go and data.go return Result throughout
Mount, MountEmbed, Open, ReadFile, ReadString, Sub, GetAsset,
GetAssetBytes, ScanAssets, GeneratePack, Extract → all return Result.
Data.ReadFile, ReadString, List, ListNames, Extract → Result.
Data.New uses Mount's Result internally.
Internal helpers (WalkDir callback, copyFile) stay error — they're
not public API.
231 tests, 77.4% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 14:13:47 +00:00
|
|
|
r := GeneratePack(pkgs[0])
|
|
|
|
|
assert.True(t, r.OK)
|
|
|
|
|
assert.Contains(t, r.Value.(string), "core.AddAsset")
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
// --- Extract (template + nested) ---
|
|
|
|
|
|
|
|
|
|
func TestExtract_WithTemplate_Good(t *testing.T) {
|
|
|
|
|
dir := t.TempDir()
|
|
|
|
|
|
|
|
|
|
// Create an in-memory FS with a template file and a plain file
|
|
|
|
|
tmplDir := os.DirFS(t.TempDir())
|
|
|
|
|
|
|
|
|
|
// Use a real temp dir with files
|
|
|
|
|
srcDir := t.TempDir()
|
|
|
|
|
os.WriteFile(srcDir+"/plain.txt", []byte("static content"), 0644)
|
|
|
|
|
os.WriteFile(srcDir+"/greeting.tmpl", []byte("Hello {{.Name}}!"), 0644)
|
|
|
|
|
os.MkdirAll(srcDir+"/sub", 0755)
|
|
|
|
|
os.WriteFile(srcDir+"/sub/nested.txt", []byte("nested"), 0644)
|
|
|
|
|
|
|
|
|
|
_ = tmplDir
|
|
|
|
|
fsys := os.DirFS(srcDir)
|
|
|
|
|
data := map[string]string{"Name": "World"}
|
|
|
|
|
|
|
|
|
|
r := Extract(fsys, dir, data)
|
|
|
|
|
assert.True(t, r.OK)
|
|
|
|
|
|
|
|
|
|
// Plain file copied
|
|
|
|
|
content, err := os.ReadFile(dir + "/plain.txt")
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
assert.Equal(t, "static content", string(content))
|
|
|
|
|
|
|
|
|
|
// Template processed and .tmpl stripped
|
|
|
|
|
greeting, err := os.ReadFile(dir + "/greeting")
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
assert.Equal(t, "Hello World!", string(greeting))
|
|
|
|
|
|
|
|
|
|
// Nested directory preserved
|
|
|
|
|
nested, err := os.ReadFile(dir + "/sub/nested.txt")
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
assert.Equal(t, "nested", string(nested))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestExtract_BadTargetDir_Ugly(t *testing.T) {
|
|
|
|
|
srcDir := t.TempDir()
|
|
|
|
|
os.WriteFile(srcDir+"/f.txt", []byte("x"), 0644)
|
|
|
|
|
r := Extract(os.DirFS(srcDir), "/nonexistent/deeply/nested/impossible", nil)
|
|
|
|
|
// Should fail gracefully, not panic
|
|
|
|
|
_ = r
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestEmbed_PathTraversal_Ugly(t *testing.T) {
|
2026-03-24 23:26:43 +00:00
|
|
|
emb := mustMountTestFS(t, "testdata")
|
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
|
|
|
r := emb.ReadFile("../../etc/passwd")
|
|
|
|
|
assert.False(t, r.OK)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestEmbed_Sub_BaseDir_Good(t *testing.T) {
|
2026-03-24 23:26:43 +00:00
|
|
|
emb := mustMountTestFS(t, "testdata")
|
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
|
|
|
r := emb.Sub("scantest")
|
|
|
|
|
assert.True(t, r.OK)
|
|
|
|
|
sub := r.Value.(*Embed)
|
|
|
|
|
assert.Equal(t, ".", sub.BaseDirectory())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestEmbed_Open_Bad(t *testing.T) {
|
2026-03-24 23:26:43 +00:00
|
|
|
emb := mustMountTestFS(t, "testdata")
|
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
|
|
|
r := emb.Open("nonexistent.txt")
|
|
|
|
|
assert.False(t, r.OK)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestEmbed_ReadDir_Bad(t *testing.T) {
|
2026-03-24 23:26:43 +00:00
|
|
|
emb := mustMountTestFS(t, "testdata")
|
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
|
|
|
r := emb.ReadDir("nonexistent")
|
|
|
|
|
assert.False(t, r.OK)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestEmbed_EmbedFS_Original_Good(t *testing.T) {
|
2026-03-24 23:26:43 +00:00
|
|
|
emb := mustMountTestFS(t, "testdata")
|
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
|
|
|
efs := emb.EmbedFS()
|
|
|
|
|
_, err := efs.ReadFile("testdata/test.txt")
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestExtract_NilData_Good(t *testing.T) {
|
|
|
|
|
dir := t.TempDir()
|
|
|
|
|
srcDir := t.TempDir()
|
|
|
|
|
os.WriteFile(srcDir+"/file.txt", []byte("no template"), 0644)
|
|
|
|
|
|
|
|
|
|
r := Extract(os.DirFS(srcDir), dir, nil)
|
|
|
|
|
assert.True(t, r.OK)
|
|
|
|
|
}
|
|
|
|
|
|
feat: embed.go and data.go return Result throughout
Mount, MountEmbed, Open, ReadFile, ReadString, Sub, GetAsset,
GetAssetBytes, ScanAssets, GeneratePack, Extract → all return Result.
Data.ReadFile, ReadString, List, ListNames, Extract → Result.
Data.New uses Mount's Result internally.
Internal helpers (WalkDir callback, copyFile) stay error — they're
not public API.
231 tests, 77.4% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 14:13:47 +00:00
|
|
|
func mustCompress(input string) string {
|
|
|
|
|
var buf bytes.Buffer
|
|
|
|
|
b64 := base64.NewEncoder(base64.StdEncoding, &buf)
|
|
|
|
|
gz, _ := gzip.NewWriterLevel(b64, gzip.BestCompression)
|
|
|
|
|
gz.Write([]byte(input))
|
|
|
|
|
gz.Close()
|
|
|
|
|
b64.Close()
|
|
|
|
|
return buf.String()
|
2026-03-20 12:10:41 +00:00
|
|
|
}
|