feat(gitea): base http client with token auth

This commit is contained in:
Mathias Bergqvist
2026-05-04 21:26:03 +02:00
parent 4dba4ca192
commit 2ecffd1b7a
2 changed files with 98 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
package gitea_test
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"gitea.d-ma.be/mathias/gitea-mcp/internal/gitea"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestClientGetsTokenInHeader(t *testing.T) {
var gotAuth string
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
gotAuth = r.Header.Get("Authorization")
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"ok":true}`))
}))
defer srv.Close()
c := gitea.NewClient(srv.URL, "test-token")
body, status, err := c.GetJSON(context.Background(), "/api/v1/user")
require.NoError(t, err)
assert.Equal(t, 200, status)
assert.Contains(t, string(body), `"ok":true`)
assert.Equal(t, "token test-token", gotAuth)
}