cleanup handlers directory
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,6 +1,7 @@
|
|||||||
# dev binary
|
# dev binary
|
||||||
ladder
|
ladder
|
||||||
tmp/main
|
tmp/main
|
||||||
|
tmp
|
||||||
|
|
||||||
VERSION
|
VERSION
|
||||||
output.css
|
output.css
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
// BEGIN: 7d5e1f7c7d5e
|
|
||||||
package handlers
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestApi(t *testing.T) {
|
|
||||||
app := fiber.New()
|
|
||||||
app.Get("/api/*", Api)
|
|
||||||
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
url string
|
|
||||||
expectedStatus int
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "valid url",
|
|
||||||
url: "https://www.google.com",
|
|
||||||
expectedStatus: http.StatusOK,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "invalid url",
|
|
||||||
url: "invalid-url",
|
|
||||||
expectedStatus: http.StatusBadRequest,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/api/"+tt.url, nil)
|
|
||||||
resp, err := app.Test(req)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Equal(t, tt.expectedStatus, resp.StatusCode)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// END: 7d5e1f7c7d5e
|
|
||||||
1
handlers/api_modifiers.go
Normal file
1
handlers/api_modifiers.go
Normal file
@@ -0,0 +1 @@
|
|||||||
|
package handlers
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
// BEGIN: 7f8d9e6d4b5c
|
|
||||||
package handlers
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestRaw(t *testing.T) {
|
|
||||||
app := fiber.New()
|
|
||||||
app.Get("/raw/*", NewRawProxySiteHandler(nil))
|
|
||||||
|
|
||||||
testCases := []struct {
|
|
||||||
name string
|
|
||||||
url string
|
|
||||||
expected string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "valid url",
|
|
||||||
url: "https://www.google.com",
|
|
||||||
expected: "<!doctype html>",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "invalid url",
|
|
||||||
url: "invalid-url",
|
|
||||||
expected: "parse invalid-url: invalid URI for request",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tc := range testCases {
|
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/raw/"+tc.url, nil)
|
|
||||||
resp, err := app.Test(req)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
t.Errorf("expected status OK; got %v", resp.Status)
|
|
||||||
}
|
|
||||||
|
|
||||||
body, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.Contains(string(body), tc.expected) {
|
|
||||||
t.Errorf("expected body to contain %q; got %q", tc.expected, string(body))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// END: 7f8d9e6d4b5c
|
|
||||||
Reference in New Issue
Block a user