diff options
author | JoramWilander <jwawilander@gmail.com> | 2018-07-10 15:01:43 -0400 |
---|---|---|
committer | JoramWilander <jwawilander@gmail.com> | 2018-07-10 15:01:43 -0400 |
commit | 6c7dc2d29ccac5f9925402f6be1a4c2a3c46c005 (patch) | |
tree | 5564a47257bf6e85aaef711980c5b0fcb4d07dcc /plugin/rpcplugin/http_test.go | |
parent | c042ffa460296587579aff54b157a5109e022f7e (diff) | |
parent | 1e1a5e5e85240f25c4faddcb24c5a29a915fe6e4 (diff) | |
download | chat-6c7dc2d29ccac5f9925402f6be1a4c2a3c46c005.tar.gz chat-6c7dc2d29ccac5f9925402f6be1a4c2a3c46c005.tar.bz2 chat-6c7dc2d29ccac5f9925402f6be1a4c2a3c46c005.zip |
Merge branch 'plugins-2'
Diffstat (limited to 'plugin/rpcplugin/http_test.go')
-rw-r--r-- | plugin/rpcplugin/http_test.go | 61 |
1 files changed, 0 insertions, 61 deletions
diff --git a/plugin/rpcplugin/http_test.go b/plugin/rpcplugin/http_test.go deleted file mode 100644 index afaaf7756..000000000 --- a/plugin/rpcplugin/http_test.go +++ /dev/null @@ -1,61 +0,0 @@ -package rpcplugin - -import ( - "io" - "io/ioutil" - "net/http" - "net/http/httptest" - "testing" - - "github.com/stretchr/testify/assert" -) - -func testHTTPResponseWriterRPC(w http.ResponseWriter, f func(w http.ResponseWriter)) { - r1, w1 := io.Pipe() - r2, w2 := io.Pipe() - - c1 := NewMuxer(NewReadWriteCloser(r1, w2), false) - defer c1.Close() - - c2 := NewMuxer(NewReadWriteCloser(r2, w1), true) - defer c2.Close() - - id, server := c1.Serve() - go ServeHTTPResponseWriter(w, server) - - remote := ConnectHTTPResponseWriter(c2.Connect(id)) - defer remote.Close() - - f(remote) -} - -func TestHTTP(t *testing.T) { - w := httptest.NewRecorder() - - testHTTPResponseWriterRPC(w, func(w http.ResponseWriter) { - headers := w.Header() - headers.Set("Test-Header-A", "a") - headers.Set("Test-Header-B", "b") - w.Header().Set("Test-Header-C", "c") - w.WriteHeader(http.StatusPaymentRequired) - n, err := w.Write([]byte("this is ")) - assert.Equal(t, 8, n) - assert.NoError(t, err) - n, err = w.Write([]byte("a test")) - assert.Equal(t, 6, n) - assert.NoError(t, err) - }) - - r := w.Result() - defer r.Body.Close() - - assert.Equal(t, http.StatusPaymentRequired, r.StatusCode) - - body, err := ioutil.ReadAll(r.Body) - assert.NoError(t, err) - assert.EqualValues(t, "this is a test", body) - - assert.Equal(t, "a", r.Header.Get("Test-Header-A")) - assert.Equal(t, "b", r.Header.Get("Test-Header-B")) - assert.Equal(t, "c", r.Header.Get("Test-Header-C")) -} |