-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
//golangcitest:args -Eresponsewriterlint | ||
package testdata | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
type notAResponseWriter struct{} | ||
|
||
func (narw notAResponseWriter) Write(in []byte) (int, error) { | ||
// actually do nothing | ||
return 42, errors.New("no") | ||
} | ||
|
||
func (narw notAResponseWriter) WriteHeader(code int) { | ||
// also do nothing | ||
} | ||
|
||
func (narw notAResponseWriter) Header() http.Header { | ||
return http.Header{} | ||
} | ||
|
||
type rwlRandom struct{} | ||
|
||
func rwlExampleOne(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Add("some header", "value") | ||
w.WriteHeader(http.StatusOK) | ||
_, _ = w.Write([]byte(`boys in the yard`)) | ||
} | ||
|
||
func rwlExampleTwo(s string, r *http.Request) error { | ||
fmt.Printf("this is a thing") | ||
|
||
return nil | ||
} | ||
|
||
func rwlFakeWriter(w notAResponseWriter) { | ||
w.Header().Add("something", "other") | ||
w.WriteHeader(420) | ||
_, _ = w.Write([]byte(`fooled ya`)) | ||
} | ||
|
||
func (b rwlRandom) method(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Add("some header", "value") | ||
w.WriteHeader(http.StatusOK) | ||
_, _ = w.Write([]byte(`boys in the yard`)) | ||
} | ||
|
||
func (b *rwlRandom) methodPointer(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Add("some header", "value") | ||
_, _ = w.Write([]byte(`boys in the yard`)) | ||
w.WriteHeader(http.StatusOK) // want "function methodPointer: http.ResponseWriter.Write is called before http.ResponseWriter.WriteHeader. Headers are already sent, this has no effect." | ||
} | ||
|
||
func rwlExampleThree(bloe http.ResponseWriter, r *http.Request) { | ||
_, _ = bloe.Write([]byte(`hellyea`)) // want "function rwlExampleThree: Multiple calls to http.ResponseWriter.Write in the same function body. This is most probably a bug." | ||
|
||
bloe.WriteHeader(http.StatusBadRequest) // want "function rwlExampleThree: Multiple calls to http.ResponseWriter.WriteHeader in the same function body. This is most probably a bug." | ||
_, _ = bloe.Write([]byte(`hellyelamdflmda`)) // want "function rwlExampleThree: Multiple calls to http.ResponseWriter.Write in the same function body. This is most probably a bug." | ||
bloe.WriteHeader(http.StatusInternalServerError) // want "function rwlExampleThree: Multiple calls to http.ResponseWriter.WriteHeader in the same function body. This is most probably a bug." | ||
|
||
bloe.Header().Set("help", "somebody") // want "function rwlExampleThree: http.ResponseWriter.Header called after calling http.ResponseWriter.Write. This has no effect." "function rwlExampleThree: http.ResponseWriter.Header called after calling http.ResponseWriter.Write. This has no effect." "function rwlExampleThree: http.ResponseWriter.Header called after calling http.ResponseWriter.WriteHeader. This has no effect." "function rwlExampleThree: http.ResponseWriter.Header called after calling http.ResponseWriter.WriteHeader. This has no effect." | ||
bloe.Header().Set("dddd", "someboddaady") // want "function rwlExampleThree: http.ResponseWriter.Header called after calling http.ResponseWriter.Write. This has no effect." "function rwlExampleThree: http.ResponseWriter.Header called after calling http.ResponseWriter.Write. This has no effect." "function rwlExampleThree: http.ResponseWriter.Header called after calling http.ResponseWriter.WriteHeader. This has no effect." "function rwlExampleThree: http.ResponseWriter.Header called after calling http.ResponseWriter.WriteHeader. This has no effect." | ||
} |