MCPcopy Index your code
hub / github.com/google/go-github / Test_FetchAndSubmitForm

Function Test_FetchAndSubmitForm

scrape/forms_test.go:92–123  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

90}
91
92func Test_FetchAndSubmitForm(t *testing.T) {
93 t.Parallel()
94 client, mux := setup(t)
95 var submitted bool
96
97 mux.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {
98 fmt.Fprint(w, `<html><form action="/submit">
99 <input type="hidden" name="hidden" value="h">
100 <input type="text" name="name">
101 </form></html>`)
102 })
103 mux.HandleFunc("/submit", func(_ http.ResponseWriter, r *http.Request) {
104 err := r.ParseForm()
105 if err != nil {
106 t.Fatalf("error parsing form: %v", err)
107 }
108 want := url.Values{"hidden": {"h"}, "name": {"n"}}
109 if got := r.Form; !cmp.Equal(got, want) {
110 t.Errorf("submitted form contained values %v, want %v", got, want)
111 }
112 submitted = true
113 })
114
115 setValues := func(values url.Values) { values.Set("name", "n") }
116 _, err := fetchAndSubmitForm(client.Client, client.baseURL.String()+"/", setValues)
117 if err != nil {
118 t.Fatalf("fetchAndSubmitForm returned err: %v", err)
119 }
120 if !submitted {
121 t.Error("form was never submitted")
122 }
123}

Callers

nothing calls this directly

Calls 5

fetchAndSubmitFormFunction · 0.85
EqualMethod · 0.80
setupFunction · 0.70
StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…