Running tool: /usr/local/go/bin/go test -timeout 30s -run ^(ExampleBuild)$
--- FAIL: ExampleBuild (0.00s)
got:
POST localhost/status?t=1 HTTP/1.1
Content-Type: application/json
want:
POST localhost/status?t=1 HTTP/1.1
Content-Type: application/json
FAIL
exit status 1
I'm trying to write test in go using the Example method. I have created a http request with header (Content-Type: application/json), query param t=1, method type POST and URL localhost.
The output in got: and want: looks to be the same, have also checked for whitespace characters. Not able to figure out what is the difference between these two here.
Not able to figure out what am I missing here.
import (
"fmt"
"net/http"
"net/http/httputil"
)
func ExampleBuild() {
req, err := http.NewRequest(http.MethodPost, "localhost/status?t=1", nil)
req.Header.Add("content-type", "application/json")
if err != nil {
panic(err)
}
str, err := httputil.DumpRequest(req, false)
if err != nil {
panic(err)
}
fmt.Printf("%s", string(str))
// Output:
// POST localhost/status?t=1 HTTP/1.1
// Content-Type: application/json
}