chore: remove cached

This commit is contained in:
Wikid82
2025-11-24 18:21:11 +00:00
parent 5b041819bb
commit 9c842e7eab
394 changed files with 0 additions and 44139 deletions

View File

@@ -1,59 +0,0 @@
package config
import (
"fmt"
"os"
"path/filepath"
)
// Config captures runtime configuration sourced from environment variables.
type Config struct {
Environment string
HTTPPort string
DatabasePath string
FrontendDir string
CaddyAdminAPI string
CaddyConfigDir string
CaddyBinary string
ImportCaddyfile string
ImportDir string
JWTSecret string
}
// Load reads env vars and falls back to defaults so the server can boot with zero configuration.
func Load() (Config, error) {
cfg := Config{
Environment: getEnv("CPM_ENV", "development"),
HTTPPort: getEnv("CPM_HTTP_PORT", "8080"),
DatabasePath: getEnv("CPM_DB_PATH", filepath.Join("data", "cpm.db")),
FrontendDir: getEnv("CPM_FRONTEND_DIR", filepath.Clean(filepath.Join("..", "frontend", "dist"))),
CaddyAdminAPI: getEnv("CPM_CADDY_ADMIN_API", "http://localhost:2019"),
CaddyConfigDir: getEnv("CPM_CADDY_CONFIG_DIR", filepath.Join("data", "caddy")),
CaddyBinary: getEnv("CPM_CADDY_BINARY", "caddy"),
ImportCaddyfile: getEnv("CPM_IMPORT_CADDYFILE", "/import/Caddyfile"),
ImportDir: getEnv("CPM_IMPORT_DIR", filepath.Join("data", "imports")),
JWTSecret: getEnv("CPM_JWT_SECRET", "change-me-in-production"),
}
if err := os.MkdirAll(filepath.Dir(cfg.DatabasePath), 0o755); err != nil {
return Config{}, fmt.Errorf("ensure data directory: %w", err)
}
if err := os.MkdirAll(cfg.CaddyConfigDir, 0o755); err != nil {
return Config{}, fmt.Errorf("ensure caddy config directory: %w", err)
}
if err := os.MkdirAll(cfg.ImportDir, 0o755); err != nil {
return Config{}, fmt.Errorf("ensure import directory: %w", err)
}
return cfg, nil
}
func getEnv(key, fallback string) string {
if val := os.Getenv(key); val != "" {
return val
}
return fallback
}

View File

@@ -1,75 +0,0 @@
package config
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestLoad(t *testing.T) {
// Save original env vars
originalEnv := os.Getenv("CPM_ENV")
defer os.Setenv("CPM_ENV", originalEnv)
// Set test env vars
os.Setenv("CPM_ENV", "test")
tempDir := t.TempDir()
os.Setenv("CPM_DB_PATH", filepath.Join(tempDir, "test.db"))
os.Setenv("CPM_CADDY_CONFIG_DIR", filepath.Join(tempDir, "caddy"))
os.Setenv("CPM_IMPORT_DIR", filepath.Join(tempDir, "imports"))
cfg, err := Load()
require.NoError(t, err)
assert.Equal(t, "test", cfg.Environment)
assert.Equal(t, filepath.Join(tempDir, "test.db"), cfg.DatabasePath)
assert.DirExists(t, filepath.Dir(cfg.DatabasePath))
assert.DirExists(t, cfg.CaddyConfigDir)
assert.DirExists(t, cfg.ImportDir)
}
func TestLoad_Defaults(t *testing.T) {
// Clear env vars to test defaults
os.Unsetenv("CPM_ENV")
os.Unsetenv("CPM_HTTP_PORT")
// We need to set paths to a temp dir to avoid creating real dirs in test
tempDir := t.TempDir()
os.Setenv("CPM_DB_PATH", filepath.Join(tempDir, "default.db"))
os.Setenv("CPM_CADDY_CONFIG_DIR", filepath.Join(tempDir, "caddy_default"))
os.Setenv("CPM_IMPORT_DIR", filepath.Join(tempDir, "imports_default"))
cfg, err := Load()
require.NoError(t, err)
assert.Equal(t, "development", cfg.Environment)
assert.Equal(t, "8080", cfg.HTTPPort)
}
func TestLoad_Error(t *testing.T) {
tempDir := t.TempDir()
filePath := filepath.Join(tempDir, "file")
f, err := os.Create(filePath)
require.NoError(t, err)
f.Close()
// Case 1: CaddyConfigDir is a file
os.Setenv("CPM_CADDY_CONFIG_DIR", filePath)
// Set other paths to valid locations to isolate the error
os.Setenv("CPM_DB_PATH", filepath.Join(tempDir, "db", "test.db"))
os.Setenv("CPM_IMPORT_DIR", filepath.Join(tempDir, "imports"))
_, err = Load()
assert.Error(t, err)
assert.Contains(t, err.Error(), "ensure caddy config directory")
// Case 2: ImportDir is a file
os.Setenv("CPM_CADDY_CONFIG_DIR", filepath.Join(tempDir, "caddy"))
os.Setenv("CPM_IMPORT_DIR", filePath)
_, err = Load()
assert.Error(t, err)
assert.Contains(t, err.Error(), "ensure import directory")
}