File tree 1 file changed +32
-0
lines changed 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -84,3 +84,35 @@ func TestExampleHandler_get_list(t *testing.T) {
84
84
t .Fatalf ("Expected a status of %d, got %d" , e , a )
85
85
}
86
86
}
87
+
88
+ func TestHttpErrorWhenHeaderDoesNotMatch (t * testing.T ) {
89
+ r , err := http .NewRequest (http .MethodGet , "/blogs" , nil )
90
+ if err != nil {
91
+ t .Fatal (err )
92
+ }
93
+ r .Header .Set (headerAccept , "application/xml" )
94
+
95
+ rr := httptest .NewRecorder ()
96
+ handler := & ExampleHandler {}
97
+ handler .ServeHTTP (rr , r )
98
+
99
+ if rr .Code != http .StatusUnsupportedMediaType {
100
+ t .Fatal ("expected Unsupported Media Type staus error" )
101
+ }
102
+ }
103
+
104
+ func TestHttpErrorWhenMethodDoesNotMatch (t * testing.T ) {
105
+ r , err := http .NewRequest (http .MethodPatch , "/blogs" , nil )
106
+ if err != nil {
107
+ t .Fatal (err )
108
+ }
109
+ r .Header .Set (headerAccept , jsonapi .MediaType )
110
+
111
+ rr := httptest .NewRecorder ()
112
+ handler := & ExampleHandler {}
113
+ handler .ServeHTTP (rr , r )
114
+
115
+ if rr .Code != http .StatusNotFound {
116
+ t .Fatal ("expected HTTP Status Not Found status error" )
117
+ }
118
+ }
You can’t perform that action at this time.
0 commit comments