Updated GitHub Actions workflow for Go tests and coverage

This commit is contained in:
Andrei Alexandru
2025-11-02 12:01:20 +02:00
parent b8a4d8d8da
commit df9a134e9b
6 changed files with 55 additions and 55 deletions

View File

@@ -0,0 +1,31 @@
package routes
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/gin-gonic/gin"
)
func TestForwardHandler(t *testing.T) {
gin.SetMode(gin.TestMode)
r := gin.Default()
RegisterForwardRoute(r)
mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("OK"))
}))
defer mockServer.Close()
req, _ := http.NewRequest("GET", "/?url="+mockServer.URL, nil)
w := httptest.NewRecorder()
r.ServeHTTP(w, req)
if w.Code != http.StatusOK {
t.Errorf("Expected 200 OK, got %d", w.Code)
}
if w.Body.String() != "OK" {
t.Errorf("Expected body 'OK', got '%s'", w.Body.String())
}
}