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" |
(...skipping 28 matching lines...) Expand all Loading... |
39 for { | 39 for { |
40 line, err := rw.Body.ReadString('\n') | 40 line, err := rw.Body.ReadString('\n') |
41 switch { | 41 switch { |
42 case err == os.EOF: | 42 case err == os.EOF: |
43 break readlines | 43 break readlines |
44 case err != nil: | 44 case err != nil: |
45 t.Fatalf("unexpected error reading from CGI: %v", err) | 45 t.Fatalf("unexpected error reading from CGI: %v", err) |
46 } | 46 } |
47 linesRead++ | 47 linesRead++ |
48 trimmedLine := strings.TrimRight(line, "\r\n") | 48 trimmedLine := strings.TrimRight(line, "\r\n") |
49 » » split := strings.Split(trimmedLine, "=", 2) | 49 » » split := strings.SplitN(trimmedLine, "=", 2) |
50 if len(split) != 2 { | 50 if len(split) != 2 { |
51 t.Fatalf("Unexpected %d parts from invalid line number %
v: %q; existing map=%v", | 51 t.Fatalf("Unexpected %d parts from invalid line number %
v: %q; existing map=%v", |
52 len(split), linesRead, line, m) | 52 len(split), linesRead, line, m) |
53 } | 53 } |
54 m[split[0]] = split[1] | 54 m[split[0]] = split[1] |
55 } | 55 } |
56 | 56 |
57 for key, expected := range expectedMap { | 57 for key, expected := range expectedMap { |
58 if got := m[key]; got != expected { | 58 if got := m[key]; got != expected { |
59 t.Errorf("for key %q got %q; expected %q", key, got, exp
ected) | 59 t.Errorf("for key %q got %q; expected %q", key, got, exp
ected) |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 Path: "testdata/test.cgi", | 294 Path: "testdata/test.cgi", |
295 Root: "/test.cgi", | 295 Root: "/test.cgi", |
296 PathLocationHandler: baseHandler, | 296 PathLocationHandler: baseHandler, |
297 } | 297 } |
298 expectedMap := map[string]string{ | 298 expectedMap := map[string]string{ |
299 "basepath": "/foo", | 299 "basepath": "/foo", |
300 "remoteaddr": "1.2.3.4", | 300 "remoteaddr": "1.2.3.4", |
301 } | 301 } |
302 runCgiTest(t, h, "GET /test.cgi?loc=/foo HTTP/1.0\nHost: example.com\n\n
", expectedMap) | 302 runCgiTest(t, h, "GET /test.cgi?loc=/foo HTTP/1.0\nHost: example.com\n\n
", expectedMap) |
303 } | 303 } |
LEFT | RIGHT |