Last active
October 15, 2017 16:24
-
-
Save kawakami-o3/42c8bb2fcd8019fda27c68974a8f8b1e to your computer and use it in GitHub Desktop.
Why not POST
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func TestWhyNotPost(t *testing.T) { | |
| testServerPort := 31337 | |
| testServerAddr := fmt.Sprintf("127.0.0.1:%d", testServerPort) | |
| testServerRootURL := fmt.Sprintf("http://%s/", testServerAddr) | |
| srv := &Server{} | |
| listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IPv4(127, 0, 0, 1), Port: testServerPort}) | |
| if err != nil { | |
| panic(err) | |
| } | |
| ch := make(chan *Request) | |
| HandleFunc("/login", func(w ResponseWriter, r *Request) { | |
| ch <- r | |
| }) | |
| go func() { | |
| srv.Serve(listener) | |
| }() | |
| go func() { | |
| values := url.Values{} | |
| values.Add("hoge", "aaa") | |
| client := Client{} | |
| // unnecessary '/' | |
| client.PostForm(testServerRootURL+"/login", values) | |
| }() | |
| var req *Request | |
| req = <-ch | |
| if req.Method != "POST" { | |
| t.Errorf("Method = %s; want POST", req.Method) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
golang/go#18570