feat: add config package with env-var loading

This commit is contained in:
Mathias Bergqvist
2026-04-17 07:37:19 +02:00
parent d3d81cab20
commit 8b8ada2676
2 changed files with 65 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
package config_test
import (
"testing"
"github.com/mathiasbq/supervisor/internal/config"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestLoadDefaults(t *testing.T) {
t.Setenv("SUPERVISOR_PORT", "")
t.Setenv("LITELLM_BASE_URL", "")
t.Setenv("LITELLM_API_KEY", "")
t.Setenv("SUPERVISOR_CONFIG_DIR", "")
cfg, err := config.Load()
require.NoError(t, err)
assert.Equal(t, "3200", cfg.Port)
assert.Equal(t, "http://iguana:4000", cfg.LiteLLMBaseURL)
assert.Equal(t, "./config/supervisor", cfg.ConfigDir)
}
func TestLoadFromEnv(t *testing.T) {
t.Setenv("SUPERVISOR_PORT", "4000")
t.Setenv("LITELLM_BASE_URL", "http://localhost:4000")
t.Setenv("LITELLM_API_KEY", "test-key")
t.Setenv("SUPERVISOR_CONFIG_DIR", "/etc/supervisor")
cfg, err := config.Load()
require.NoError(t, err)
assert.Equal(t, "4000", cfg.Port)
assert.Equal(t, "http://localhost:4000", cfg.LiteLLMBaseURL)
assert.Equal(t, "test-key", cfg.LiteLLMAPIKey)
assert.Equal(t, "/etc/supervisor", cfg.ConfigDir)
}