mirror of
https://github.com/buger/goreplay.git
synced 2024-04-21 12:32:02 +00:00
fix echo.sh test
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
function log {
|
function log {
|
||||||
if [[ ! -v GOR_TEST ]]; then # if we are not testing
|
if [[ -n "$GOR_TEST" ]]; then # if we are not testing
|
||||||
# Logging to stderr, because stdout/stdin used for data transfer
|
# Logging to stderr, because stdout/stdin used for data transfer
|
||||||
>&2 echo "[DEBUG][ECHO] $1"
|
>&2 echo "[DEBUG][ECHO] $1"
|
||||||
fi
|
fi
|
||||||
|
|||||||
+6
-7
@@ -3,20 +3,19 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"github.com/buger/goreplay/proto"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"syscall"
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/buger/goreplay/proto"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const echoSh = "./examples/middleware/echo.sh"
|
const echoSh = "./examples/middleware/echo.sh"
|
||||||
const tokenModifier = "go run ./examples/middleware/token_modifier.go"
|
const tokenModifier = "go run ./examples/middleware/token_modifier.go"
|
||||||
|
|
||||||
var noDebug = append(syscall.Environ(), "GOR_TEST=1")
|
var withDebug = append(syscall.Environ(), "GOR_TEST=1")
|
||||||
|
|
||||||
func initMiddleware(cmd *exec.Cmd, cancl context.CancelFunc, l PluginReader, c func(error)) *Middleware {
|
func initMiddleware(cmd *exec.Cmd, cancl context.CancelFunc, l PluginReader, c func(error)) *Middleware {
|
||||||
var m Middleware
|
var m Middleware
|
||||||
@@ -52,7 +51,7 @@ func initCmd(command string, env []string) (*exec.Cmd, context.CancelFunc) {
|
|||||||
func TestMiddlewareEarlyClose(t *testing.T) {
|
func TestMiddlewareEarlyClose(t *testing.T) {
|
||||||
quit := make(chan struct{})
|
quit := make(chan struct{})
|
||||||
in := NewTestInput()
|
in := NewTestInput()
|
||||||
cmd, cancl := initCmd(echoSh, noDebug)
|
cmd, cancl := initCmd(echoSh, withDebug)
|
||||||
midd := initMiddleware(cmd, cancl, in, func(err error) {
|
midd := initMiddleware(cmd, cancl, in, func(err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if e, ok := err.(*exec.ExitError); ok {
|
if e, ok := err.(*exec.ExitError); ok {
|
||||||
@@ -93,7 +92,7 @@ func TestTokenMiddleware(t *testing.T) {
|
|||||||
quit := make(chan struct{})
|
quit := make(chan struct{})
|
||||||
in := NewTestInput()
|
in := NewTestInput()
|
||||||
in.skipHeader = true
|
in.skipHeader = true
|
||||||
cmd, cancl := initCmd(tokenModifier, noDebug)
|
cmd, cancl := initCmd(tokenModifier, withDebug)
|
||||||
midd := initMiddleware(cmd, cancl, in, func(err error) {})
|
midd := initMiddleware(cmd, cancl, in, func(err error) {})
|
||||||
req := []byte("1 932079936fa4306fc308d67588178d17d823647c 1439818823587396305 200\nGET /token HTTP/1.1\r\nHost: example.org\r\n\r\n")
|
req := []byte("1 932079936fa4306fc308d67588178d17d823647c 1439818823587396305 200\nGET /token HTTP/1.1\r\nHost: example.org\r\n\r\n")
|
||||||
res := []byte("2 932079936fa4306fc308d67588178d17d823647c 1439818823587396305 200\nHTTP/1.1 200 OK\r\nContent-Length: 10\r\nContent-Type: text/plain; charset=utf-8\r\n\r\n17d823647c")
|
res := []byte("2 932079936fa4306fc308d67588178d17d823647c 1439818823587396305 200\nHTTP/1.1 200 OK\r\nContent-Length: 10\r\nContent-Type: text/plain; charset=utf-8\r\n\r\n17d823647c")
|
||||||
@@ -103,7 +102,7 @@ func TestTokenMiddleware(t *testing.T) {
|
|||||||
if msg.Meta[0] == '1' && !bytes.Equal(payloadID(msg.Meta), payloadID(req)) {
|
if msg.Meta[0] == '1' && !bytes.Equal(payloadID(msg.Meta), payloadID(req)) {
|
||||||
token, _, _ := proto.PathParam(msg.Data, []byte("token"))
|
token, _, _ := proto.PathParam(msg.Data, []byte("token"))
|
||||||
if !bytes.Equal(token, proto.Body(rep)) {
|
if !bytes.Equal(token, proto.Body(rep)) {
|
||||||
t.Error("expected the token to be equal to the replayed responses's token")
|
t.Errorf("expected the token %s to be equal to the replayed response's token %s", token, proto.Body(rep))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
atomic.AddUint32(&count, 1)
|
atomic.AddUint32(&count, 1)
|
||||||
@@ -131,7 +130,7 @@ func TestMiddlewareWithPrettify(t *testing.T) {
|
|||||||
Settings.PrettifyHTTP = true
|
Settings.PrettifyHTTP = true
|
||||||
quit := make(chan struct{})
|
quit := make(chan struct{})
|
||||||
in := NewTestInput()
|
in := NewTestInput()
|
||||||
cmd, cancl := initCmd(echoSh, noDebug)
|
cmd, cancl := initCmd(echoSh, withDebug)
|
||||||
midd := initMiddleware(cmd, cancl, in, func(err error) {})
|
midd := initMiddleware(cmd, cancl, in, func(err error) {})
|
||||||
var b1 = []byte("POST / HTTP/1.1\r\nHost: example.org\r\nTransfer-Encoding: chunked\r\n\r\n4\r\nWiki\r\n5\r\npedia\r\nE\r\n in\r\n\r\nchunks.\r\n0\r\n\r\n")
|
var b1 = []byte("POST / HTTP/1.1\r\nHost: example.org\r\nTransfer-Encoding: chunked\r\n\r\n4\r\nWiki\r\n5\r\npedia\r\nE\r\n in\r\n\r\nchunks.\r\n0\r\n\r\n")
|
||||||
var b2 = []byte("POST / HTTP/1.1\r\nHost: example.org\r\nContent-Length: 25\r\n\r\nWikipedia in\r\n\r\nchunks.")
|
var b2 = []byte("POST / HTTP/1.1\r\nHost: example.org\r\nContent-Length: 25\r\n\r\nWikipedia in\r\n\r\nchunks.")
|
||||||
|
|||||||
Reference in New Issue
Block a user