Implements core/paths (Config/Data/State/Cache/Runtime/Log/Bin
directory resolution with canonical-vs-search-dir separation, XDG on
Unix, native APPDATA/LOCALAPPDATA/PROGRAMDATA layering on Windows,
~/Library on macOS Desktop, injectable environment/platform for
deterministic cross-platform tests) and core/config (file search,
first-match resolution, layered YAML merging, safe ${VAR} expansion,
Explain/doctor introspection) on top of the shared Application/
Kind/Scope model in the core package.
72 lines
1.7 KiB
Go
72 lines
1.7 KiB
Go
package core
|
|
|
|
import "testing"
|
|
|
|
func TestApplicationValidate(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
app Application
|
|
wantErr bool
|
|
}{
|
|
{"valid", Application{Name: "yet"}, false},
|
|
{"valid-with-dash", Application{Name: "yapl-oci"}, false},
|
|
{"empty", Application{Name: ""}, true},
|
|
{"slash", Application{Name: "ye/t"}, true},
|
|
{"backslash", Application{Name: `ye\t`}, true},
|
|
{"dot", Application{Name: "."}, true},
|
|
{"dotdot", Application{Name: ".."}, true},
|
|
{"leading-space", Application{Name: " yet"}, true},
|
|
{"trailing-space", Application{Name: "yet "}, true},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
err := tc.app.Validate()
|
|
if (err != nil) != tc.wantErr {
|
|
t.Fatalf("Validate() error = %v, wantErr %v", err, tc.wantErr)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestApplicationEnvPrefix(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
want string
|
|
}{
|
|
{"yet", "YET"},
|
|
{"yapl-oci", "YAPL_OCI"},
|
|
{"yasta", "YASTA"},
|
|
}
|
|
for _, tc := range cases {
|
|
app := Application{Name: tc.name}
|
|
if got := app.EnvPrefix(); got != tc.want {
|
|
t.Errorf("Application{Name: %q}.EnvPrefix() = %q, want %q", tc.name, got, tc.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestApplicationKindString(t *testing.T) {
|
|
cases := map[ApplicationKind]string{
|
|
CLI: "cli",
|
|
Desktop: "desktop",
|
|
Service: "service",
|
|
}
|
|
for kind, want := range cases {
|
|
if got := kind.String(); got != want {
|
|
t.Errorf("%v.String() = %q, want %q", int(kind), got, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestScopeString(t *testing.T) {
|
|
cases := map[Scope]string{
|
|
UserScope: "user",
|
|
SystemScope: "system",
|
|
}
|
|
for scope, want := range cases {
|
|
if got := scope.String(); got != want {
|
|
t.Errorf("%v.String() = %q, want %q", int(scope), got, want)
|
|
}
|
|
}
|
|
}
|