Skip to content

Commit

Permalink
fix: more fixes to merging
Browse files Browse the repository at this point in the history
  • Loading branch information
ConsoleTVs committed Apr 19, 2024
1 parent 76ed9bb commit 4ad1ec5
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 5 deletions.
3 changes: 2 additions & 1 deletion handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ func handleError(writer http.ResponseWriter, request *http.Request, err error, p

if parent != nil {
builder := NewProblem(err, http.StatusInternalServerError).
Respond(request)
Respond(request).
Status(0)

parent.
Merge(builder).
Expand Down
87 changes: 83 additions & 4 deletions testing_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package akumu_test

import (
"errors"
"net/http"
"testing"

Expand All @@ -11,6 +12,18 @@ func handler(request *http.Request) error {
return akumu.Response(http.StatusOK)
}

func handler2(request *http.Request) error {
return akumu.Failed(errors.New("failure"))
}

func handler3(request *http.Request) error {
return akumu.Response(http.StatusNotImplemented).Failed(errors.New("failure"))
}

func handler4(request *http.Request) error {
return errors.New("failure")
}

func TestHandler(t *testing.T) {
request, err := http.NewRequest("GET", "/", nil)

Expand All @@ -21,7 +34,11 @@ func TestHandler(t *testing.T) {
response := akumu.Record(handler, request)

if response.Code != http.StatusOK {
t.Fatalf("unexpected status code: %d", response.Code)
t.Fatalf(
"unexpected status code: expected %d, got %d",
http.StatusOK,
response.Code,
)
}
}

Expand All @@ -32,10 +49,14 @@ func TestHTTPHandler(t *testing.T) {
t.Fatalf("unable to create request: %s", err)
}

response := akumu.Record(handler, request)
response := akumu.RecordHandler(akumu.Handler(handler), request)

if response.Code != http.StatusOK {
t.Fatalf("unexpected status code: %d", response.Code)
t.Fatalf(
"unexpected status code: expected %d, got %d",
http.StatusOK,
response.Code,
)
}
}

Expand All @@ -50,6 +71,64 @@ func TestHTTPServer(t *testing.T) {
response := akumu.RecordServer(server, request)

if response.Code != http.StatusOK {
t.Fatalf("unexpected status code: %d", response.Code)
t.Fatalf(
"unexpected status code: expected %d, got %d",
http.StatusOK,
response.Code,
)
}
}

func TestHandler2(t *testing.T) {
request, err := http.NewRequest("GET", "/", nil)

if err != nil {
t.Fatalf("unable to create request: %s", err)
}

response := akumu.Record(handler2, request)

if response.Code != http.StatusInternalServerError {
t.Fatalf(
"unexpected status code: expected %d, got %d",
http.StatusInternalServerError,
response.Code,
)
}
}

func TestHandler3(t *testing.T) {
request, err := http.NewRequest("GET", "/", nil)

if err != nil {
t.Fatalf("unable to create request: %s", err)
}

response := akumu.Record(handler3, request)

if response.Code != http.StatusNotImplemented {
t.Fatalf(
"unexpected status code: expected %d, got %d",
http.StatusNotImplemented,
response.Code,
)
}
}

func TestHandler4(t *testing.T) {
request, err := http.NewRequest("GET", "/", nil)

if err != nil {
t.Fatalf("unable to create request: %s", err)
}

response := akumu.Record(handler4, request)

if response.Code != http.StatusInternalServerError {
t.Fatalf(
"unexpected status code: expected %d, got %d",
http.StatusInternalServerError,
response.Code,
)
}
}

0 comments on commit 4ad1ec5

Please sign in to comment.