| 70 | } |
| 71 | |
| 72 | func TestFormValuesDatasource(t *testing.T) { |
| 73 | method := "POST" |
| 74 | urlString := "http://example.com/form/test" |
| 75 | body := strings.NewReader("name=Inigo+Montoya&fingers=6") |
| 76 | |
| 77 | request, err := http.NewRequest(method, urlString, body) |
| 78 | |
| 79 | // Canary |
| 80 | if err != nil { |
| 81 | t.Error("! Error constructing a request.", err) |
| 82 | } |
| 83 | |
| 84 | // For POST requests with a body from a form the Content-Type header needs |
| 85 | // to be set or the form body isn't processed. |
| 86 | request.Header.Set("Content-Type", "application/x-www-form-urlencoded; param=value") |
| 87 | |
| 88 | ds := new(FormValuesDatasource).Init(request) |
| 89 | |
| 90 | if ds.Value("name").(string) != "Inigo Montoya" { |
| 91 | t.Error("! Prepare to die.") |
| 92 | } |
| 93 | |
| 94 | if ds.Value("fingers") != "6" { |
| 95 | t.Error("! Expected six fingers, but got less.") |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | func TestPathDatasource(t *testing.T) { |
| 100 | ds := new(PathDatasource).Init("/foo/bar") |