Fmt and docs

This commit is contained in:
Denis Makogon
2017-10-07 02:59:08 +03:00
parent 6141344e5f
commit e4684096f7
3 changed files with 24 additions and 23 deletions

View File

@@ -2,33 +2,37 @@ package protocol
import (
"bytes"
"testing"
"encoding/json"
"io"
"io/ioutil"
"net/http"
"net/url"
"io/ioutil"
"io"
"encoding/json"
"reflect"
"testing"
)
type RequestData struct {
A string `json:"a"`
}
type fuckReed struct {
Body RequestData `json:"body"`
}
func TestJSONProtocolDumpJSONRequestWithData(t *testing.T) {
req := &http.Request{
Method: http.MethodPost,
URL: &url.URL{
Scheme: "http",
Host: "localhost:8080",
Path: "/v1/apps",
Scheme: "http",
Host: "localhost:8080",
Path: "/v1/apps",
RawQuery: "something=something&etc=etc",
},
ProtoMajor: 1,
ProtoMinor: 1,
Header: http.Header{
"Host": []string{"localhost:8080"},
"User-Agent": []string{"curl/7.51.0"},
"Host": []string{"localhost:8080"},
"User-Agent": []string{"curl/7.51.0"},
"Content-Type": []string{"application/json"},
},
Host: "localhost:8080",
@@ -39,7 +43,7 @@ func TestJSONProtocolDumpJSONRequestWithData(t *testing.T) {
req.Body = ioutil.NopCloser(&buf)
r, w := io.Pipe()
proto := JSONProtocol{w,r}
proto := JSONProtocol{w, r}
go func() {
err := proto.DumpJSON(req)
if err != nil {
@@ -73,16 +77,16 @@ func TestJSONProtocolDumpJSONRequestWithoutData(t *testing.T) {
req := &http.Request{
Method: http.MethodPost,
URL: &url.URL{
Scheme: "http",
Host: "localhost:8080",
Path: "/v1/apps",
Scheme: "http",
Host: "localhost:8080",
Path: "/v1/apps",
RawQuery: "something=something&etc=etc",
},
ProtoMajor: 1,
ProtoMinor: 1,
Header: http.Header{
"Host": []string{"localhost:8080"},
"User-Agent": []string{"curl/7.51.0"},
"Host": []string{"localhost:8080"},
"User-Agent": []string{"curl/7.51.0"},
"Content-Type": []string{"application/json"},
},
Host: "localhost:8080",
@@ -91,7 +95,7 @@ func TestJSONProtocolDumpJSONRequestWithoutData(t *testing.T) {
req.Body = ioutil.NopCloser(&buf)
r, w := io.Pipe()
proto := JSONProtocol{w,r}
proto := JSONProtocol{w, r}
go func() {
err := proto.DumpJSON(req)
if err != nil {