feat: add config package with env-var loading
This commit is contained in:
36
internal/config/config_test.go
Normal file
36
internal/config/config_test.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user