cleanup handlers directory

This commit is contained in:
Kevin Pham
2023-12-07 10:37:05 -06:00
parent 3aad9cf406
commit 0b084f44ae
6 changed files with 2 additions and 104 deletions

1
.gitignore vendored
View File

@@ -1,6 +1,7 @@
# dev binary
ladder
tmp/main
tmp
VERSION
output.css

View File

@@ -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

View File

@@ -0,0 +1 @@
package handlers

View File

@@ -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