Skip to content

Commit bf9d233

Browse files
committed
fix echo.sh test
1 parent 9e2754f commit bf9d233

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

examples/middleware/echo.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#
99

1010
function log {
11-
if [[ ! -v GOR_TEST ]]; then # if we are not testing
11+
if [[ -n "$GOR_TEST" ]]; then # if we are not testing
1212
# Logging to stderr, because stdout/stdin used for data transfer
1313
>&2 echo "[DEBUG][ECHO] $1"
1414
fi

middleware_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,19 @@ package main
33
import (
44
"bytes"
55
"context"
6+
"github.com/buger/goreplay/proto"
67
"os"
78
"os/exec"
89
"strings"
910
"sync/atomic"
1011
"syscall"
1112
"testing"
12-
13-
"github.com/buger/goreplay/proto"
1413
)
1514

1615
const echoSh = "./examples/middleware/echo.sh"
1716
const tokenModifier = "go run ./examples/middleware/token_modifier.go"
1817

19-
var noDebug = append(syscall.Environ(), "GOR_TEST=1")
18+
var withDebug = append(syscall.Environ(), "GOR_TEST=1")
2019

2120
func initMiddleware(cmd *exec.Cmd, cancl context.CancelFunc, l PluginReader, c func(error)) *Middleware {
2221
var m Middleware
@@ -52,7 +51,7 @@ func initCmd(command string, env []string) (*exec.Cmd, context.CancelFunc) {
5251
func TestMiddlewareEarlyClose(t *testing.T) {
5352
quit := make(chan struct{})
5453
in := NewTestInput()
55-
cmd, cancl := initCmd(echoSh, noDebug)
54+
cmd, cancl := initCmd(echoSh, withDebug)
5655
midd := initMiddleware(cmd, cancl, in, func(err error) {
5756
if err != nil {
5857
if e, ok := err.(*exec.ExitError); ok {
@@ -93,7 +92,7 @@ func TestTokenMiddleware(t *testing.T) {
9392
quit := make(chan struct{})
9493
in := NewTestInput()
9594
in.skipHeader = true
96-
cmd, cancl := initCmd(tokenModifier, noDebug)
95+
cmd, cancl := initCmd(tokenModifier, withDebug)
9796
midd := initMiddleware(cmd, cancl, in, func(err error) {})
9897
req := []byte("1 932079936fa4306fc308d67588178d17d823647c 1439818823587396305 200\nGET /token HTTP/1.1\r\nHost: example.org\r\n\r\n")
9998
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) {
103102
if msg.Meta[0] == '1' && !bytes.Equal(payloadID(msg.Meta), payloadID(req)) {
104103
token, _, _ := proto.PathParam(msg.Data, []byte("token"))
105104
if !bytes.Equal(token, proto.Body(rep)) {
106-
t.Error("expected the token to be equal to the replayed responses's token")
105+
t.Errorf("expected the token %s to be equal to the replayed response's token %s", token, proto.Body(rep))
107106
}
108107
}
109108
atomic.AddUint32(&count, 1)
@@ -131,7 +130,7 @@ func TestMiddlewareWithPrettify(t *testing.T) {
131130
Settings.PrettifyHTTP = true
132131
quit := make(chan struct{})
133132
in := NewTestInput()
134-
cmd, cancl := initCmd(echoSh, noDebug)
133+
cmd, cancl := initCmd(echoSh, withDebug)
135134
midd := initMiddleware(cmd, cancl, in, func(err error) {})
136135
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")
137136
var b2 = []byte("POST / HTTP/1.1\r\nHost: example.org\r\nContent-Length: 25\r\n\r\nWikipedia in\r\n\r\nchunks.")

0 commit comments

Comments
 (0)