Updated GitHub Actions workflow for Go tests and coverage
This commit is contained in:
31
NewProxy/routes/forward_test.go
Normal file
31
NewProxy/routes/forward_test.go
Normal 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())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user