summaryrefslogtreecommitdiff
path: root/handler_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'handler_test.go')
-rw-r--r--handler_test.go22
1 files changed, 11 insertions, 11 deletions
diff --git a/handler_test.go b/handler_test.go
index a83ef3b..18ef562 100644
--- a/handler_test.go
+++ b/handler_test.go
@@ -13,19 +13,19 @@ import (
)
func TestFallthrough(t *testing.T) {
- h1 := func(ctx context.Context, req *gus.Request) *gus.Response {
+ h1 := gus.HandlerFunc(func(ctx context.Context, req *gus.Request) *gus.Response {
if req.Path == "/one" {
return gemini.Success("text/gemini", bytes.NewBufferString("one"))
}
return nil
- }
+ })
- h2 := func(ctx context.Context, req *gus.Request) *gus.Response {
+ h2 := gus.HandlerFunc(func(ctx context.Context, req *gus.Request) *gus.Response {
if req.Path == "/two" {
return gemini.Success("text/gemini", bytes.NewBufferString("two"))
}
return nil
- }
+ })
fth := gus.FallthroughHandler(h1, h2)
@@ -34,7 +34,7 @@ func TestFallthrough(t *testing.T) {
t.Fatalf("url.Parse: %s", err.Error())
}
- resp := fth(context.Background(), &gus.Request{URL: u})
+ resp := fth.Handle(context.Background(), &gus.Request{URL: u})
if resp.Status != gemini.StatusSuccess {
t.Errorf("expected status %d, got %d", gemini.StatusSuccess, resp.Status)
@@ -57,7 +57,7 @@ func TestFallthrough(t *testing.T) {
t.Fatalf("url.Parse: %s", err.Error())
}
- resp = fth(context.Background(), &gus.Request{URL: u})
+ resp = fth.Handle(context.Background(), &gus.Request{URL: u})
if resp.Status != gemini.StatusSuccess {
t.Errorf("expected status %d, got %d", gemini.StatusSuccess, resp.Status)
@@ -80,7 +80,7 @@ func TestFallthrough(t *testing.T) {
t.Fatalf("url.Parse: %s", err.Error())
}
- resp = fth(context.Background(), &gus.Request{URL: u})
+ resp = fth.Handle(context.Background(), &gus.Request{URL: u})
if resp != nil {
t.Errorf("expected nil, got %+v", resp)
@@ -91,9 +91,9 @@ func TestFilter(t *testing.T) {
pred := func(ctx context.Context, req *gus.Request) bool {
return strings.HasPrefix(req.Path, "/allow")
}
- base := func(ctx context.Context, req *gus.Request) *gus.Response {
+ base := gus.HandlerFunc(func(ctx context.Context, req *gus.Request) *gus.Response {
return gemini.Success("text/gemini", bytes.NewBufferString("allowed!"))
- }
+ })
handler := gus.Filter(pred, nil)(base)
u, err := url.Parse("gemini://test.local/allow/please")
@@ -101,7 +101,7 @@ func TestFilter(t *testing.T) {
t.Fatalf("url.Parse: %s", err.Error())
}
- resp := handler(context.Background(), &gus.Request{URL: u})
+ resp := handler.Handle(context.Background(), &gus.Request{URL: u})
if resp.Status != gemini.StatusSuccess {
t.Errorf("expected status %d, got %d", gemini.StatusSuccess, resp.Status)
}
@@ -111,7 +111,7 @@ func TestFilter(t *testing.T) {
t.Fatalf("url.Parse: %s", err.Error())
}
- resp = handler(context.Background(), &gus.Request{URL: u})
+ resp = handler.Handle(context.Background(), &gus.Request{URL: u})
if resp != nil {
t.Errorf("expected nil, got %+v", resp)
}