OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [net/] [http/] [cgi/] [child_test.go] - Blame information for rev 747

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// Copyright 2011 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
4
 
5
// Tests for CGI (the child process perspective)
6
 
7
package cgi
8
 
9
import (
10
        "testing"
11
)
12
 
13
func TestRequest(t *testing.T) {
14
        env := map[string]string{
15
                "SERVER_PROTOCOL": "HTTP/1.1",
16
                "REQUEST_METHOD":  "GET",
17
                "HTTP_HOST":       "example.com",
18
                "HTTP_REFERER":    "elsewhere",
19
                "HTTP_USER_AGENT": "goclient",
20
                "HTTP_FOO_BAR":    "baz",
21
                "REQUEST_URI":     "/path?a=b",
22
                "CONTENT_LENGTH":  "123",
23
                "CONTENT_TYPE":    "text/xml",
24
                "HTTPS":           "1",
25
                "REMOTE_ADDR":     "5.6.7.8",
26
        }
27
        req, err := RequestFromMap(env)
28
        if err != nil {
29
                t.Fatalf("RequestFromMap: %v", err)
30
        }
31
        if g, e := req.UserAgent(), "goclient"; e != g {
32
                t.Errorf("expected UserAgent %q; got %q", e, g)
33
        }
34
        if g, e := req.Method, "GET"; e != g {
35
                t.Errorf("expected Method %q; got %q", e, g)
36
        }
37
        if g, e := req.Header.Get("Content-Type"), "text/xml"; e != g {
38
                t.Errorf("expected Content-Type %q; got %q", e, g)
39
        }
40
        if g, e := req.ContentLength, int64(123); e != g {
41
                t.Errorf("expected ContentLength %d; got %d", e, g)
42
        }
43
        if g, e := req.Referer(), "elsewhere"; e != g {
44
                t.Errorf("expected Referer %q; got %q", e, g)
45
        }
46
        if req.Header == nil {
47
                t.Fatalf("unexpected nil Header")
48
        }
49
        if g, e := req.Header.Get("Foo-Bar"), "baz"; e != g {
50
                t.Errorf("expected Foo-Bar %q; got %q", e, g)
51
        }
52
        if g, e := req.URL.String(), "http://example.com/path?a=b"; e != g {
53
                t.Errorf("expected URL %q; got %q", e, g)
54
        }
55
        if g, e := req.FormValue("a"), "b"; e != g {
56
                t.Errorf("expected FormValue(a) %q; got %q", e, g)
57
        }
58
        if req.Trailer == nil {
59
                t.Errorf("unexpected nil Trailer")
60
        }
61
        if req.TLS == nil {
62
                t.Errorf("expected non-nil TLS")
63
        }
64
        if e, g := "5.6.7.8:0", req.RemoteAddr; e != g {
65
                t.Errorf("RemoteAddr: got %q; want %q", g, e)
66
        }
67
}
68
 
69
func TestRequestWithoutHost(t *testing.T) {
70
        env := map[string]string{
71
                "SERVER_PROTOCOL": "HTTP/1.1",
72
                "HTTP_HOST":       "",
73
                "REQUEST_METHOD":  "GET",
74
                "REQUEST_URI":     "/path?a=b",
75
                "CONTENT_LENGTH":  "123",
76
        }
77
        req, err := RequestFromMap(env)
78
        if err != nil {
79
                t.Fatalf("RequestFromMap: %v", err)
80
        }
81
        if req.URL == nil {
82
                t.Fatalf("unexpected nil URL")
83
        }
84
        if g, e := req.URL.String(), "/path?a=b"; e != g {
85
                t.Errorf("expected URL %q; got %q", e, g)
86
        }
87
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.