Skip to content

Commit 966a416

Browse files
committed
Move some Content Type checking tests
As a preparation to remove the deprecated ResourceHandler, make sure no test is loast by dispatching the content of handler_test.go to the right places. This changeset is about the Content Type checking tests.
1 parent 3152f30 commit 966a416

File tree

2 files changed

+6
-31
lines changed

2 files changed

+6
-31
lines changed

rest/content_type_checker_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,10 @@ func TestContentTypeCheckerMiddleware(t *testing.T) {
3939
req.Header.Set("Content-Type", "text/x-json")
4040
recorded = test.RunRequest(t, handler, req)
4141
recorded.CodeIs(415)
42+
43+
// JSON payload with correct content type but incorrect charset
44+
req = test.MakeSimpleRequest("POST", "http://localhost/", map[string]string{"Id": "123"})
45+
req.Header.Set("Content-Type", "application/json; charset=ISO-8859-1")
46+
recorded = test.RunRequest(t, handler, req)
47+
recorded.CodeIs(415)
4248
}

rest/handler_test.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -46,37 +46,6 @@ func TestHandler(t *testing.T) {
4646
recorded.ContentTypeIsJson()
4747
recorded.BodyIs(`{"Id":"123"}`)
4848

49-
// valid post resource
50-
recorded = test.RunRequest(t, &handler, test.MakeSimpleRequest(
51-
"POST", "http://1.2.3.4/r/123", &map[string]string{"Test": "Test"}))
52-
recorded.CodeIs(200)
53-
recorded.ContentTypeIsJson()
54-
recorded.BodyIs(`{"Test":"Test"}`)
55-
56-
// broken Content-Type post resource
57-
request := test.MakeSimpleRequest("POST", "http://1.2.3.4/r/123", &map[string]string{"Test": "Test"})
58-
request.Header.Set("Content-Type", "text/html")
59-
recorded = test.RunRequest(t, &handler, request)
60-
recorded.CodeIs(415)
61-
recorded.ContentTypeIsJson()
62-
recorded.BodyIs(`{"Error":"Bad Content-Type or charset, expected 'application/json'"}`)
63-
64-
// broken Content-Type post resource
65-
request = test.MakeSimpleRequest("POST", "http://1.2.3.4/r/123", &map[string]string{"Test": "Test"})
66-
request.Header.Set("Content-Type", "application/json; charset=ISO-8859-1")
67-
recorded = test.RunRequest(t, &handler, request)
68-
recorded.CodeIs(415)
69-
recorded.ContentTypeIsJson()
70-
recorded.BodyIs(`{"Error":"Bad Content-Type or charset, expected 'application/json'"}`)
71-
72-
// Content-Type post resource with charset
73-
request = test.MakeSimpleRequest("POST", "http://1.2.3.4/r/123", &map[string]string{"Test": "Test"})
74-
request.Header.Set("Content-Type", "application/json;charset=UTF-8")
75-
recorded = test.RunRequest(t, &handler, request)
76-
recorded.CodeIs(200)
77-
recorded.ContentTypeIsJson()
78-
recorded.BodyIs(`{"Test":"Test"}`)
79-
8049
// auto 405 on undefined route (wrong method)
8150
recorded = test.RunRequest(t, &handler, test.MakeSimpleRequest("DELETE", "http://1.2.3.4/r/123", nil))
8251
recorded.CodeIs(405)

0 commit comments

Comments
 (0)