fix echo.sh test

This commit is contained in:
dimagolomozy
2021-08-04 13:48:36 +03:00
parent 9e2754f673
commit bf9d233ab0
2 changed files with 7 additions and 8 deletions
+1 -1
View File
@@ -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
+6 -7
View File
@@ -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.")