45 lines
964 B
Go
45 lines
964 B
Go
package middleware
|
|
|
|
import (
|
|
"context"
|
|
"io/ioutil"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"src.dualinventive.com/go/lib/dilog"
|
|
)
|
|
|
|
func TestUDP_postsRequestWithBody(t *testing.T) {
|
|
if testing.Short() {
|
|
t.Skip("skipping test in short mode.")
|
|
}
|
|
|
|
//given
|
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
body, err := ioutil.ReadAll(r.Body)
|
|
assert.Nil(t, err)
|
|
assert.Contains(t, string(body), "\"value\":\"74657374\"")
|
|
assert.Equal(t, "someHeaderValue", r.Header.Get("someHeaderName"))
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
}))
|
|
defer ts.Close()
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
|
|
mw := NewEchoMiddleware(ctx, dilog.NewTestLogger(t), ts.URL, map[string]string{
|
|
"someHeaderName": "someHeaderValue",
|
|
}, 100)
|
|
h := mw.UDP(func(p []byte) {
|
|
//Do nothing on purpose
|
|
})
|
|
|
|
//when
|
|
h([]byte("test"))
|
|
time.Sleep(time.Second)
|
|
}
|