Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(767)

Unified Diff: 2014/testing/httprecorder.go

Issue 108170043: code review 108170043: "Testing Techniques" talk (Closed)
Patch Set: diff -r 7094cf573469 https://code.google.com/p/go.talks Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « 2014/testing/go1.1.png ('k') | 2014/testing/httpserver.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: 2014/testing/httprecorder.go
===================================================================
new file mode 100644
--- /dev/null
+++ b/2014/testing/httprecorder.go
@@ -0,0 +1,26 @@
+package main
+
+import (
+ "fmt"
+ "log"
+ "net/http"
+ "net/http/httptest"
+)
+
+func main() {
+ // START OMIT
+ handler := func(w http.ResponseWriter, r *http.Request) {
+ http.Error(w, "something failed", http.StatusInternalServerError)
+ }
+
+ req, err := http.NewRequest("GET", "http://example.com/foo", nil)
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ w := httptest.NewRecorder()
+ handler(w, req)
+
+ fmt.Printf("%d - %s", w.Code, w.Body.String())
+ // STOP OMIT
+}
« no previous file with comments | « 2014/testing/go1.1.png ('k') | 2014/testing/httpserver.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b