feat: add core.Env() — read-only system information registry
Env is environment, Config is ours. Provides centralised access to
system facts (OS, ARCH, hostname, user, directories, timestamps)
via string key lookup, populated once at package init.
Keys: OS, ARCH, GO, DS, PS, HOSTNAME, USER, PID, NUM_CPU,
DIR_HOME, DIR_CONFIG, DIR_CACHE, DIR_DATA, DIR_TMP, DIR_CWD,
DIR_DOWNLOADS, DIR_CODE, CORE_START.
17 tests covering all keys + unknown key + Core instance accessor.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 09:08:26 +00:00
|
|
|
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
|
|
|
|
|
|
package core_test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
core "dappco.re/go/core"
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
)
|
|
|
|
|
|
2026-03-25 19:23:11 +00:00
|
|
|
func TestInfo_Env_OS_Good(t *testing.T) {
|
|
|
|
|
v := core.Env("OS")
|
|
|
|
|
assert.NotEmpty(t, v)
|
|
|
|
|
assert.Contains(t, []string{"darwin", "linux", "windows"}, v)
|
feat: add core.Env() — read-only system information registry
Env is environment, Config is ours. Provides centralised access to
system facts (OS, ARCH, hostname, user, directories, timestamps)
via string key lookup, populated once at package init.
Keys: OS, ARCH, GO, DS, PS, HOSTNAME, USER, PID, NUM_CPU,
DIR_HOME, DIR_CONFIG, DIR_CACHE, DIR_DATA, DIR_TMP, DIR_CWD,
DIR_DOWNLOADS, DIR_CODE, CORE_START.
17 tests covering all keys + unknown key + Core instance accessor.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 09:08:26 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-25 19:23:11 +00:00
|
|
|
func TestInfo_Env_ARCH_Good(t *testing.T) {
|
|
|
|
|
v := core.Env("ARCH")
|
|
|
|
|
assert.NotEmpty(t, v)
|
|
|
|
|
assert.Contains(t, []string{"amd64", "arm64", "386"}, v)
|
feat: add core.Env() — read-only system information registry
Env is environment, Config is ours. Provides centralised access to
system facts (OS, ARCH, hostname, user, directories, timestamps)
via string key lookup, populated once at package init.
Keys: OS, ARCH, GO, DS, PS, HOSTNAME, USER, PID, NUM_CPU,
DIR_HOME, DIR_CONFIG, DIR_CACHE, DIR_DATA, DIR_TMP, DIR_CWD,
DIR_DOWNLOADS, DIR_CODE, CORE_START.
17 tests covering all keys + unknown key + Core instance accessor.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 09:08:26 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-25 19:23:11 +00:00
|
|
|
func TestInfo_Env_GO_Good(t *testing.T) {
|
|
|
|
|
assert.True(t, core.HasPrefix(core.Env("GO"), "go"))
|
feat: add core.Env() — read-only system information registry
Env is environment, Config is ours. Provides centralised access to
system facts (OS, ARCH, hostname, user, directories, timestamps)
via string key lookup, populated once at package init.
Keys: OS, ARCH, GO, DS, PS, HOSTNAME, USER, PID, NUM_CPU,
DIR_HOME, DIR_CONFIG, DIR_CACHE, DIR_DATA, DIR_TMP, DIR_CWD,
DIR_DOWNLOADS, DIR_CODE, CORE_START.
17 tests covering all keys + unknown key + Core instance accessor.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 09:08:26 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-25 19:23:11 +00:00
|
|
|
func TestInfo_Env_DS_Good(t *testing.T) {
|
|
|
|
|
ds := core.Env("DS")
|
|
|
|
|
assert.Contains(t, []string{"/", "\\"}, ds)
|
feat: add core.Env() — read-only system information registry
Env is environment, Config is ours. Provides centralised access to
system facts (OS, ARCH, hostname, user, directories, timestamps)
via string key lookup, populated once at package init.
Keys: OS, ARCH, GO, DS, PS, HOSTNAME, USER, PID, NUM_CPU,
DIR_HOME, DIR_CONFIG, DIR_CACHE, DIR_DATA, DIR_TMP, DIR_CWD,
DIR_DOWNLOADS, DIR_CODE, CORE_START.
17 tests covering all keys + unknown key + Core instance accessor.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 09:08:26 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-25 19:23:11 +00:00
|
|
|
func TestInfo_Env_PS_Good(t *testing.T) {
|
|
|
|
|
ps := core.Env("PS")
|
|
|
|
|
assert.Contains(t, []string{":", ";"}, ps)
|
feat: add core.Env() — read-only system information registry
Env is environment, Config is ours. Provides centralised access to
system facts (OS, ARCH, hostname, user, directories, timestamps)
via string key lookup, populated once at package init.
Keys: OS, ARCH, GO, DS, PS, HOSTNAME, USER, PID, NUM_CPU,
DIR_HOME, DIR_CONFIG, DIR_CACHE, DIR_DATA, DIR_TMP, DIR_CWD,
DIR_DOWNLOADS, DIR_CODE, CORE_START.
17 tests covering all keys + unknown key + Core instance accessor.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 09:08:26 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-25 19:23:11 +00:00
|
|
|
func TestInfo_Env_DIR_HOME_Good(t *testing.T) {
|
|
|
|
|
home := core.Env("DIR_HOME")
|
|
|
|
|
assert.NotEmpty(t, home)
|
|
|
|
|
assert.True(t, core.PathIsAbs(home), "DIR_HOME should be absolute")
|
feat: add core.Env() — read-only system information registry
Env is environment, Config is ours. Provides centralised access to
system facts (OS, ARCH, hostname, user, directories, timestamps)
via string key lookup, populated once at package init.
Keys: OS, ARCH, GO, DS, PS, HOSTNAME, USER, PID, NUM_CPU,
DIR_HOME, DIR_CONFIG, DIR_CACHE, DIR_DATA, DIR_TMP, DIR_CWD,
DIR_DOWNLOADS, DIR_CODE, CORE_START.
17 tests covering all keys + unknown key + Core instance accessor.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 09:08:26 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-25 19:23:11 +00:00
|
|
|
func TestInfo_Env_DIR_TMP_Good(t *testing.T) {
|
|
|
|
|
assert.NotEmpty(t, core.Env("DIR_TMP"))
|
feat: add core.Env() — read-only system information registry
Env is environment, Config is ours. Provides centralised access to
system facts (OS, ARCH, hostname, user, directories, timestamps)
via string key lookup, populated once at package init.
Keys: OS, ARCH, GO, DS, PS, HOSTNAME, USER, PID, NUM_CPU,
DIR_HOME, DIR_CONFIG, DIR_CACHE, DIR_DATA, DIR_TMP, DIR_CWD,
DIR_DOWNLOADS, DIR_CODE, CORE_START.
17 tests covering all keys + unknown key + Core instance accessor.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 09:08:26 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-25 19:23:11 +00:00
|
|
|
func TestInfo_Env_DIR_CONFIG_Good(t *testing.T) {
|
|
|
|
|
assert.NotEmpty(t, core.Env("DIR_CONFIG"))
|
feat: add core.Env() — read-only system information registry
Env is environment, Config is ours. Provides centralised access to
system facts (OS, ARCH, hostname, user, directories, timestamps)
via string key lookup, populated once at package init.
Keys: OS, ARCH, GO, DS, PS, HOSTNAME, USER, PID, NUM_CPU,
DIR_HOME, DIR_CONFIG, DIR_CACHE, DIR_DATA, DIR_TMP, DIR_CWD,
DIR_DOWNLOADS, DIR_CODE, CORE_START.
17 tests covering all keys + unknown key + Core instance accessor.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 09:08:26 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-25 19:23:11 +00:00
|
|
|
func TestInfo_Env_DIR_CACHE_Good(t *testing.T) {
|
|
|
|
|
assert.NotEmpty(t, core.Env("DIR_CACHE"))
|
feat: add core.Env() — read-only system information registry
Env is environment, Config is ours. Provides centralised access to
system facts (OS, ARCH, hostname, user, directories, timestamps)
via string key lookup, populated once at package init.
Keys: OS, ARCH, GO, DS, PS, HOSTNAME, USER, PID, NUM_CPU,
DIR_HOME, DIR_CONFIG, DIR_CACHE, DIR_DATA, DIR_TMP, DIR_CWD,
DIR_DOWNLOADS, DIR_CODE, CORE_START.
17 tests covering all keys + unknown key + Core instance accessor.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 09:08:26 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-25 19:23:11 +00:00
|
|
|
func TestInfo_Env_HOSTNAME_Good(t *testing.T) {
|
|
|
|
|
assert.NotEmpty(t, core.Env("HOSTNAME"))
|
feat: add core.Env() — read-only system information registry
Env is environment, Config is ours. Provides centralised access to
system facts (OS, ARCH, hostname, user, directories, timestamps)
via string key lookup, populated once at package init.
Keys: OS, ARCH, GO, DS, PS, HOSTNAME, USER, PID, NUM_CPU,
DIR_HOME, DIR_CONFIG, DIR_CACHE, DIR_DATA, DIR_TMP, DIR_CWD,
DIR_DOWNLOADS, DIR_CODE, CORE_START.
17 tests covering all keys + unknown key + Core instance accessor.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 09:08:26 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-25 19:23:11 +00:00
|
|
|
func TestInfo_Env_USER_Good(t *testing.T) {
|
feat: add core.Env() — read-only system information registry
Env is environment, Config is ours. Provides centralised access to
system facts (OS, ARCH, hostname, user, directories, timestamps)
via string key lookup, populated once at package init.
Keys: OS, ARCH, GO, DS, PS, HOSTNAME, USER, PID, NUM_CPU,
DIR_HOME, DIR_CONFIG, DIR_CACHE, DIR_DATA, DIR_TMP, DIR_CWD,
DIR_DOWNLOADS, DIR_CODE, CORE_START.
17 tests covering all keys + unknown key + Core instance accessor.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 09:08:26 +00:00
|
|
|
assert.NotEmpty(t, core.Env("USER"))
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-25 19:23:11 +00:00
|
|
|
func TestInfo_Env_PID_Good(t *testing.T) {
|
feat: add core.Env() — read-only system information registry
Env is environment, Config is ours. Provides centralised access to
system facts (OS, ARCH, hostname, user, directories, timestamps)
via string key lookup, populated once at package init.
Keys: OS, ARCH, GO, DS, PS, HOSTNAME, USER, PID, NUM_CPU,
DIR_HOME, DIR_CONFIG, DIR_CACHE, DIR_DATA, DIR_TMP, DIR_CWD,
DIR_DOWNLOADS, DIR_CODE, CORE_START.
17 tests covering all keys + unknown key + Core instance accessor.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 09:08:26 +00:00
|
|
|
assert.NotEmpty(t, core.Env("PID"))
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-25 19:23:11 +00:00
|
|
|
func TestInfo_Env_NUM_CPU_Good(t *testing.T) {
|
feat: add core.Env() — read-only system information registry
Env is environment, Config is ours. Provides centralised access to
system facts (OS, ARCH, hostname, user, directories, timestamps)
via string key lookup, populated once at package init.
Keys: OS, ARCH, GO, DS, PS, HOSTNAME, USER, PID, NUM_CPU,
DIR_HOME, DIR_CONFIG, DIR_CACHE, DIR_DATA, DIR_TMP, DIR_CWD,
DIR_DOWNLOADS, DIR_CODE, CORE_START.
17 tests covering all keys + unknown key + Core instance accessor.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 09:08:26 +00:00
|
|
|
assert.NotEmpty(t, core.Env("NUM_CPU"))
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-25 19:23:11 +00:00
|
|
|
func TestInfo_Env_CORE_START_Good(t *testing.T) {
|
feat: add core.Env() — read-only system information registry
Env is environment, Config is ours. Provides centralised access to
system facts (OS, ARCH, hostname, user, directories, timestamps)
via string key lookup, populated once at package init.
Keys: OS, ARCH, GO, DS, PS, HOSTNAME, USER, PID, NUM_CPU,
DIR_HOME, DIR_CONFIG, DIR_CACHE, DIR_DATA, DIR_TMP, DIR_CWD,
DIR_DOWNLOADS, DIR_CODE, CORE_START.
17 tests covering all keys + unknown key + Core instance accessor.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 09:08:26 +00:00
|
|
|
ts := core.Env("CORE_START")
|
|
|
|
|
require.NotEmpty(t, ts)
|
|
|
|
|
_, err := time.Parse(time.RFC3339, ts)
|
|
|
|
|
assert.NoError(t, err, "CORE_START should be valid RFC3339")
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-25 19:23:11 +00:00
|
|
|
func TestInfo_Env_Bad_Unknown(t *testing.T) {
|
feat: add core.Env() — read-only system information registry
Env is environment, Config is ours. Provides centralised access to
system facts (OS, ARCH, hostname, user, directories, timestamps)
via string key lookup, populated once at package init.
Keys: OS, ARCH, GO, DS, PS, HOSTNAME, USER, PID, NUM_CPU,
DIR_HOME, DIR_CONFIG, DIR_CACHE, DIR_DATA, DIR_TMP, DIR_CWD,
DIR_DOWNLOADS, DIR_CODE, CORE_START.
17 tests covering all keys + unknown key + Core instance accessor.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 09:08:26 +00:00
|
|
|
assert.Equal(t, "", core.Env("NOPE"))
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-25 19:23:11 +00:00
|
|
|
func TestInfo_Env_Good_CoreInstance(t *testing.T) {
|
2026-03-24 21:50:05 +00:00
|
|
|
c := core.New()
|
feat: add core.Env() — read-only system information registry
Env is environment, Config is ours. Provides centralised access to
system facts (OS, ARCH, hostname, user, directories, timestamps)
via string key lookup, populated once at package init.
Keys: OS, ARCH, GO, DS, PS, HOSTNAME, USER, PID, NUM_CPU,
DIR_HOME, DIR_CONFIG, DIR_CACHE, DIR_DATA, DIR_TMP, DIR_CWD,
DIR_DOWNLOADS, DIR_CODE, CORE_START.
17 tests covering all keys + unknown key + Core instance accessor.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 09:08:26 +00:00
|
|
|
assert.Equal(t, core.Env("OS"), c.Env("OS"))
|
|
|
|
|
assert.Equal(t, core.Env("DIR_HOME"), c.Env("DIR_HOME"))
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-25 19:23:11 +00:00
|
|
|
func TestInfo_EnvKeys_Good(t *testing.T) {
|
feat: add core.Env() — read-only system information registry
Env is environment, Config is ours. Provides centralised access to
system facts (OS, ARCH, hostname, user, directories, timestamps)
via string key lookup, populated once at package init.
Keys: OS, ARCH, GO, DS, PS, HOSTNAME, USER, PID, NUM_CPU,
DIR_HOME, DIR_CONFIG, DIR_CACHE, DIR_DATA, DIR_TMP, DIR_CWD,
DIR_DOWNLOADS, DIR_CODE, CORE_START.
17 tests covering all keys + unknown key + Core instance accessor.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 09:08:26 +00:00
|
|
|
keys := core.EnvKeys()
|
|
|
|
|
assert.NotEmpty(t, keys)
|
|
|
|
|
assert.Contains(t, keys, "OS")
|
|
|
|
|
assert.Contains(t, keys, "DIR_HOME")
|
|
|
|
|
assert.Contains(t, keys, "CORE_START")
|
|
|
|
|
}
|