From ec780ad623401ad610492104b6dc39154c5c943b Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 8 Jan 2020 11:51:48 +0800 Subject: [PATCH] more tests --- context_test.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/context_test.go b/context_test.go index e3a1865..0fe28aa 100644 --- a/context_test.go +++ b/context_test.go @@ -473,3 +473,38 @@ func TestContextActionTag(t *testing.T) { expect(t, recorder.Code, http.StatusOK) expect(t, buff.String(), "lunny") } + +type AnyAnyAction struct { + JSON +} + +func (a *AnyAnyAction) Any() interface{} { + return map[string]string{ + "here": "anyany", + } +} + +func TestContextAnyAny(t *testing.T) { + buff := bytes.NewBufferString("") + recorder := httptest.NewRecorder() + recorder.Body = buff + + o := New( + Logging(), + Recovery(false), + Return(), + Param(), + Contexts(), + ) + o.Any("/", new(AnyAnyAction)) + + req, err := http.NewRequest("GET", "http://localhost:8000/", nil) + if err != nil { + t.Error(err) + } + + o.ServeHTTP(recorder, req) + + expect(t, recorder.Code, http.StatusOK) + expect(t, strings.TrimSpace(buff.String()), `{"here":"anyany"}`) +} -- 2.40.1