Skip to content

Commit 7fc8c20

Browse files
committed
test case improvements
1 parent b6a479d commit 7fc8c20

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

testing/testsuite_test.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ func testHandle(w http.ResponseWriter, r *http.Request) {
203203
if r.Method == "GET" {
204204
if r.URL.Path == "/" {
205205
_, _ = w.Write([]byte(`this is testcase homepage`))
206+
return
206207
}
207208
}
208209

@@ -223,11 +224,13 @@ func testHandle(w http.ResponseWriter, r *http.Request) {
223224
}
224225

225226
handleFileUpload(w, r)
227+
return
226228
}
227229

228230
if r.Method == "DELETE" {
229231
if r.URL.Path == "/purchases/10001" {
230232
w.WriteHeader(http.StatusOK)
233+
return
231234
}
232235
}
233236

@@ -246,26 +249,33 @@ func testHandle(w http.ResponseWriter, r *http.Request) {
246249
if r.Method == "PATCH" {
247250
if r.URL.Path == "/purchases/10003" {
248251
w.WriteHeader(http.StatusNoContent)
252+
return
249253
}
250254
}
251255

252256
w.WriteHeader(http.StatusNotFound)
253-
254257
}
255258

256259
func handleFileUpload(w http.ResponseWriter, r *http.Request) {
257260
if r.URL.Path == "/upload" {
258261
_ = r.ParseMultipartForm(10e6)
259-
262+
var buf bytes.Buffer
260263
for _, fhdrs := range r.MultipartForm.File {
261264
for _, hdr := range fhdrs {
262265
dotPos := strings.LastIndex(hdr.Filename, ".")
263266
fname := fmt.Sprintf("%s-%v%s", hdr.Filename[:dotPos], time.Now().Unix(), hdr.Filename[dotPos:])
264-
_, _ = w.Write([]byte(fmt.Sprintf("Firstname: %v\nLastname: %v\nFile: %v\nHeader: %v\nUploaded as: %v\n",
265-
r.FormValue("first_name"), r.FormValue("last_name"), hdr.Filename, hdr.Header, fname)))
267+
_, _ = buf.WriteString(fmt.Sprintf(
268+
"Firstname: %v\nLastname: %v\nFile: %v\nHeader: %v\nUploaded as: %v\n",
269+
r.FormValue("first_name"),
270+
r.FormValue("last_name"),
271+
hdr.Filename,
272+
hdr.Header,
273+
fname))
266274
}
267275
}
268276

277+
_, _ = w.Write(buf.Bytes())
278+
269279
return
270280
}
271281
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy