Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ func TestDo_ResponseEmpty(t *testing.T) {
if err == nil || err.(*Error).Body != "Bad Request" {
t.Errorf("Even with ResponseEmpty error should read the body")
}

resEm, err := Do[ResponseEmpty]("key.value")
if err != nil {
t.Error(err)
}
if resEm.Status != 200 {
t.Errorf("response status isn't 200")
}
if resEm.Headers["Content-type"] != "application/json" {
t.Errorf("wrong headers")
}
}

func TestDo_Error(t *testing.T) {
Expand Down
13 changes: 13 additions & 0 deletions to_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ func TestToHandlerFunc_EmptyOut(t *testing.T) {
assert(t, mw.body, ``)
}


func TestToHandlerFunc_RequestEmpty(t *testing.T) {
f := ToHandlerFunc(func(in RequestEmpty) (J, error) {
return M{"name": "Lola"}, nil
})
mw := newMockWriter()
r, err := http.NewRequest("", "", bytes.NewBuffer(nil))
assert(t, err, nil)
f(mw, r)
assert(t, mw.status, 200)
assert(t, mw.body, `{"name":"Lola"}`)
}

// This test should fail to compile on go1.21 and successfully run on go1.22.
// Don't forget to update go.mod to 1.22 before running.
//func TestToHandlerFunc_MultiplePathValue(t *testing.T) {
Expand Down
4 changes: 4 additions & 0 deletions wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ func (r Request[T]) WithHeader(name, value string) Request[T] {
// Can be used with the wrappers Response and Request or to fit the signature of ApplyFunc.
type Empty struct{}


type ResponseEmpty = Response[Empty]
type RequestEmpty = Request[Empty]

func isResponseWrapper(v any) bool {
if v == nil {
return false
Expand Down
Loading