LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Tests for package cgi | 5 // Tests for package cgi |
6 | 6 |
7 package cgi | 7 package cgi |
8 | 8 |
9 import ( | 9 import ( |
10 "bufio" | 10 "bufio" |
11 "fmt" | 11 "fmt" |
12 "io" | 12 "io" |
13 "net" | 13 "net" |
14 "net/http" | 14 "net/http" |
15 "net/http/httptest" | 15 "net/http/httptest" |
16 "os" | 16 "os" |
17 "os/exec" | 17 "os/exec" |
18 "path/filepath" | 18 "path/filepath" |
19 "runtime" | 19 "runtime" |
20 "strconv" | 20 "strconv" |
21 "strings" | 21 "strings" |
22 "syscall" | |
23 "testing" | 22 "testing" |
24 "time" | 23 "time" |
25 ) | 24 ) |
26 | 25 |
27 func newRequest(httpreq string) *http.Request { | 26 func newRequest(httpreq string) *http.Request { |
28 buf := bufio.NewReader(strings.NewReader(httpreq)) | 27 buf := bufio.NewReader(strings.NewReader(httpreq)) |
29 req, err := http.ReadRequest(buf) | 28 req, err := http.ReadRequest(buf) |
30 if err != nil { | 29 if err != nil { |
31 panic("cgi: bogus http request in test: " + httpreq) | 30 panic("cgi: bogus http request in test: " + httpreq) |
32 } | 31 } |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 t.Fatalf("invalid X-CGI-Pid value") | 332 t.Fatalf("invalid X-CGI-Pid value") |
334 } | 333 } |
335 | 334 |
336 var buf [5000]byte | 335 var buf [5000]byte |
337 n, err := io.ReadFull(res.Body, buf[:]) | 336 n, err := io.ReadFull(res.Body, buf[:]) |
338 if err != nil { | 337 if err != nil { |
339 t.Fatalf("ReadFull: %d bytes, %v", n, err) | 338 t.Fatalf("ReadFull: %d bytes, %v", n, err) |
340 } | 339 } |
341 | 340 |
342 childRunning := func() bool { | 341 childRunning := func() bool { |
343 » » p, err := os.FindProcess(pid) | 342 » » _, err := os.FindProcess(pid) |
344 » » if err != nil { | 343 » » return err == nil |
345 » » » return false | |
346 » » } | |
347 » » return p.Signal(syscall.Signal(0)) == nil | |
348 } | 344 } |
349 | 345 |
350 if !childRunning() { | 346 if !childRunning() { |
351 t.Fatalf("pre-conn.Close, expected child to be running") | 347 t.Fatalf("pre-conn.Close, expected child to be running") |
352 } | 348 } |
353 conn.Close() | 349 conn.Close() |
354 | 350 |
355 tries := 0 | 351 tries := 0 |
356 for tries < 25 && childRunning() { | 352 for tries < 25 && childRunning() { |
357 time.Sleep(50 * time.Millisecond * time.Duration(tries)) | 353 time.Sleep(50 * time.Millisecond * time.Duration(tries)) |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 "SCRIPT_FILENAME=" + cgifile, | 453 "SCRIPT_FILENAME=" + cgifile, |
458 "REQUEST_URI=/foo/bar"}, | 454 "REQUEST_URI=/foo/bar"}, |
459 } | 455 } |
460 expectedMap := map[string]string{ | 456 expectedMap := map[string]string{ |
461 "cwd": cwd, | 457 "cwd": cwd, |
462 "env-SCRIPT_FILENAME": cgifile, | 458 "env-SCRIPT_FILENAME": cgifile, |
463 "env-REQUEST_URI": "/foo/bar", | 459 "env-REQUEST_URI": "/foo/bar", |
464 } | 460 } |
465 runCgiTest(t, h, "GET /test.cgi HTTP/1.0\nHost: example.com\n\n", expect
edMap) | 461 runCgiTest(t, h, "GET /test.cgi HTTP/1.0\nHost: example.com\n\n", expect
edMap) |
466 } | 462 } |
LEFT | RIGHT |