go-scm/jobrunner/handlers/testhelper_test.go
Virgil 305aa0da6f
Some checks failed
Security Scan / security (push) Failing after 8s
Test / test (push) Successful in 4m12s
chore(ax): normalize SPDX header identifier
2026-03-30 00:54:20 +00:00

37 lines
1 KiB
Go

// SPDX-License-Identifier: EUPL-1.2
package handlers
import (
strings "dappco.re/go/core/scm/internal/ax/stringsx"
"net/http"
"testing"
"github.com/stretchr/testify/require"
"dappco.re/go/core/scm/forge"
)
// forgejoVersionResponse is the JSON response for /api/v1/version.
const forgejoVersionResponse = `{"version":"9.0.0"}`
// withVersion wraps an HTTP handler to also serve the Forgejo version endpoint
// that the SDK calls during NewClient initialization.
func withVersion(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasSuffix(r.URL.Path, "/version") {
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(forgejoVersionResponse))
return
}
next.ServeHTTP(w, r)
})
}
// newTestForgeClient creates a forge.Client pointing at the given test server URL.
func newTestForgeClient(t *testing.T, url string) *forge.Client {
t.Helper()
client, err := forge.New(url, "test-token")
require.NoError(t, err)
return client
}