Drop one-shot tmp/axe scripts and agent i18n scratch so the Gitea tree is deployable.
62 lines
1.7 KiB
Go
62 lines
1.7 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestApplyEnvFileDoesNotOverrideExisting(t *testing.T) {
|
|
dir := t.TempDir()
|
|
path := filepath.Join(dir, ".env")
|
|
if err := os.WriteFile(path, []byte("DOTENV_TEST_KEY=fromfile\nDOTENV_ONLY_FILE=only\n"), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Setenv("DOTENV_TEST_KEY", "fromprocess")
|
|
t.Setenv("DOTENV_ONLY_FILE", "")
|
|
// Empty existing must still block override (matches tests that clear keys).
|
|
_ = os.Unsetenv("DOTENV_ONLY_FILE")
|
|
|
|
if err := applyEnvFile(path); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := os.Getenv("DOTENV_TEST_KEY"); got != "fromprocess" {
|
|
t.Fatalf("override: got %q", got)
|
|
}
|
|
if got := os.Getenv("DOTENV_ONLY_FILE"); got != "only" {
|
|
t.Fatalf("missing fill: got %q", got)
|
|
}
|
|
}
|
|
|
|
func TestFindMonorepoRootFromAPIDir(t *testing.T) {
|
|
cwd, err := os.Getwd()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// This test file lives under apps/api/internal/config — walk should find repo root.
|
|
root, ok := findMonorepoRoot()
|
|
if !ok {
|
|
t.Fatalf("findMonorepoRoot from cwd %s", cwd)
|
|
}
|
|
if _, err := os.Stat(filepath.Join(root, "apps", "api")); err != nil {
|
|
t.Fatalf("root %s missing apps/api: %v", root, err)
|
|
}
|
|
if _, err := os.Stat(filepath.Join(root, "apps", "web")); err != nil {
|
|
t.Fatalf("root %s missing apps/web: %v", root, err)
|
|
}
|
|
}
|
|
|
|
func TestLoadDotEnvPathOverride(t *testing.T) {
|
|
dir := t.TempDir()
|
|
path := filepath.Join(dir, "custom.env")
|
|
if err := os.WriteFile(path, []byte("DOTENV_PATH_ONLY=yes\n"), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Setenv("DOTENV_PATH", path)
|
|
_ = os.Unsetenv("DOTENV_PATH_ONLY")
|
|
loadDotEnv()
|
|
if got := os.Getenv("DOTENV_PATH_ONLY"); got != "yes" {
|
|
t.Fatalf("DOTENV_PATH load: got %q", got)
|
|
}
|
|
}
|