MCPcopy Create free account
hub / github.com/Masterminds/cookoo / TestFormValuesDatasource

Function TestFormValuesDatasource

web/datasources_test.go:72–97  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

70}
71
72func 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
99func TestPathDatasource(t *testing.T) {
100 ds := new(PathDatasource).Init("/foo/bar")

Callers

nothing calls this directly

Calls 3

InitMethod · 0.65
ValueMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected