feat(config): env-var loading
Add internal/config package with Config struct and Load() function. Reads GITEA_BASE_URL, GITEA_API_TOKEN, GITEA_MCP_ALLOWED_OWNERS, GITEA_MCP_ORIGIN_ALLOWLIST, GITEA_MCP_PORT with sensible defaults. Wire cfg.Port into main.go. TDD: tests written first, then impl. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
38
internal/config/config_test.go
Normal file
38
internal/config/config_test.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package config_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gitea.d-ma.be/mathias/gitea-mcp/internal/config"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestLoadDefaults(t *testing.T) {
|
||||
t.Setenv("GITEA_BASE_URL", "")
|
||||
t.Setenv("GITEA_API_TOKEN", "")
|
||||
t.Setenv("GITEA_MCP_ALLOWED_OWNERS", "")
|
||||
t.Setenv("GITEA_MCP_ORIGIN_ALLOWLIST", "")
|
||||
t.Setenv("GITEA_MCP_PORT", "")
|
||||
|
||||
cfg, err := config.Load()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "8080", cfg.Port)
|
||||
assert.Equal(t, []string{"mathias"}, cfg.AllowedOwners)
|
||||
}
|
||||
|
||||
func TestLoadFromEnv(t *testing.T) {
|
||||
t.Setenv("GITEA_BASE_URL", "https://gitea.d-ma.be")
|
||||
t.Setenv("GITEA_API_TOKEN", "test-token")
|
||||
t.Setenv("GITEA_MCP_ALLOWED_OWNERS", "mathias,acme")
|
||||
t.Setenv("GITEA_MCP_ORIGIN_ALLOWLIST", "https://claude.ai,https://api.anthropic.com")
|
||||
t.Setenv("GITEA_MCP_PORT", "9000")
|
||||
|
||||
cfg, err := config.Load()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "https://gitea.d-ma.be", cfg.GiteaBaseURL)
|
||||
assert.Equal(t, "test-token", cfg.GiteaAPIToken)
|
||||
assert.Equal(t, []string{"mathias", "acme"}, cfg.AllowedOwners)
|
||||
assert.Equal(t, []string{"https://claude.ai", "https://api.anthropic.com"}, cfg.OriginAllowlist)
|
||||
assert.Equal(t, "9000", cfg.Port)
|
||||
}
|
||||
Reference in New Issue
Block a user