From bf9d233ab0c26973c02e9c88c759bda1d4d481c6 Mon Sep 17 00:00:00 2001 From: dimagolomozy Date: Wed, 4 Aug 2021 13:48:36 +0300 Subject: [PATCH] fix echo.sh test --- examples/middleware/echo.sh | 2 +- middleware_test.go | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/examples/middleware/echo.sh b/examples/middleware/echo.sh index ad22956..a3074e7 100755 --- a/examples/middleware/echo.sh +++ b/examples/middleware/echo.sh @@ -8,7 +8,7 @@ # 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 >&2 echo "[DEBUG][ECHO] $1" fi diff --git a/middleware_test.go b/middleware_test.go index c5884e7..e7c123a 100644 --- a/middleware_test.go +++ b/middleware_test.go @@ -3,20 +3,19 @@ package main import ( "bytes" "context" + "github.com/buger/goreplay/proto" "os" "os/exec" "strings" "sync/atomic" "syscall" "testing" - - "github.com/buger/goreplay/proto" ) const echoSh = "./examples/middleware/echo.sh" 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 { var m Middleware @@ -52,7 +51,7 @@ func initCmd(command string, env []string) (*exec.Cmd, context.CancelFunc) { func TestMiddlewareEarlyClose(t *testing.T) { quit := make(chan struct{}) in := NewTestInput() - cmd, cancl := initCmd(echoSh, noDebug) + cmd, cancl := initCmd(echoSh, withDebug) midd := initMiddleware(cmd, cancl, in, func(err error) { if err != nil { if e, ok := err.(*exec.ExitError); ok { @@ -93,7 +92,7 @@ func TestTokenMiddleware(t *testing.T) { quit := make(chan struct{}) in := NewTestInput() in.skipHeader = true - cmd, cancl := initCmd(tokenModifier, noDebug) + cmd, cancl := initCmd(tokenModifier, withDebug) 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") 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)) { token, _, _ := proto.PathParam(msg.Data, []byte("token")) 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) @@ -131,7 +130,7 @@ func TestMiddlewareWithPrettify(t *testing.T) { Settings.PrettifyHTTP = true quit := make(chan struct{}) in := NewTestInput() - cmd, cancl := initCmd(echoSh, noDebug) + cmd, cancl := initCmd(echoSh, withDebug) 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 b2 = []byte("POST / HTTP/1.1\r\nHost: example.org\r\nContent-Length: 25\r\n\r\nWikipedia in\r\n\r\nchunks.")