Skip to content

Commit

Permalink
Merge branch 'main' into fallBackOnMiss
Browse files Browse the repository at this point in the history
  • Loading branch information
gouravkrosx authored May 26, 2024
2 parents e75e070 + 142b1bc commit 1f076b4
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 13 deletions.
6 changes: 3 additions & 3 deletions pkg/core/proxy/integrations/generic/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func encodeGeneric(ctx context.Context, logger *zap.Logger, reqBuf []byte, clien

bufStr := string(reqBuf)
dataType := models.String
if !util.IsASCIIPrintable(string(reqBuf)) {
if !util.IsASCII(string(reqBuf)) {
bufStr = util.EncodeBase64(reqBuf)
dataType = "binary"
}
Expand Down Expand Up @@ -144,7 +144,7 @@ func encodeGeneric(ctx context.Context, logger *zap.Logger, reqBuf []byte, clien

bufStr := string(buffer)
buffDataType := models.String
if !util.IsASCIIPrintable(string(buffer)) {
if !util.IsASCII(string(buffer)) {
bufStr = util.EncodeBase64(buffer)
buffDataType = "binary"
}
Expand Down Expand Up @@ -176,7 +176,7 @@ func encodeGeneric(ctx context.Context, logger *zap.Logger, reqBuf []byte, clien

bufStr := string(buffer)
buffDataType := models.String
if !util.IsASCIIPrintable(string(buffer)) {
if !util.IsASCII(string(buffer)) {
bufStr = base64.StdEncoding.EncodeToString(buffer)
buffDataType = "binary"
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/proxy/integrations/generic/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func findExactMatch(tcsMocks []*models.Mock, reqBuffs [][]byte) int {
for requestIndex, reqBuff := range reqBuffs {

bufStr := string(reqBuff)
if !util.IsASCIIPrintable(string(reqBuff)) {
if !util.IsASCII(string(reqBuff)) {
bufStr = util.EncodeBase64(reqBuff)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/core/proxy/integrations/http/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func findStringMatch(_ string, mockString []string) int {
minDist := int(^uint(0) >> 1) // Initialize with max int value
bestMatch := -1
for idx, req := range mockString {
if !util.IsASCIIPrintable(mockString[idx]) {
if !util.IsASCII(mockString[idx]) {
continue
}

Expand Down Expand Up @@ -293,7 +293,7 @@ func fuzzyMatch(tcsMocks []*models.Mock, reqBuff []byte) (bool, *models.Mock) {
mockString[i] = tcsMocks[i].Spec.HTTPReq.Body
}
// find the closest match
if util.IsASCIIPrintable(string(reqBuff)) {
if util.IsASCII(string(reqBuff)) {
idx := findStringMatch(string(reqBuff), mockString)
if idx != -1 {
return true, tcsMocks[idx]
Expand Down
4 changes: 2 additions & 2 deletions pkg/core/proxy/integrations/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"unicode"
)

func IsASCIIPrintable(s string) bool {
func IsASCII(s string) bool {
for _, r := range s {
if r > unicode.MaxASCII || !unicode.IsPrint(r) {
if r > unicode.MaxASCII {
return false
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/core/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ func (p *Proxy) StartProxy(ctx context.Context, opts core.ProxyOptions) error {
// set up the CA for tls connections
err = SetupCA(ctx, p.logger)
if err != nil {
utils.LogError(p.logger, err, "failed to setup CA")
return err
// log the error and continue
p.logger.Warn("failed to setup CA", zap.Error(err))
}
g, ok := ctx.Value(models.ErrGroupKey).(*errgroup.Group)
if !ok {
Expand Down
3 changes: 2 additions & 1 deletion pkg/service/replay/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,8 @@ func (r *Replayer) RunTestSet(ctx context.Context, testSetID string, testRunID s
resp, loopErr := requestMockemulator.SimulateRequest(runTestSetCtx, appID, testCase, testSetID)
if loopErr != nil {
utils.LogError(r.logger, err, "failed to simulate request")
break
failure++
continue
}

consumedMocks, err := r.instrumentation.GetConsumedMocks(runTestSetCtx, appID)
Expand Down
6 changes: 4 additions & 2 deletions pkg/service/replay/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ type Telemetry interface {
MockTestRun(utilizedMocks int)
}

// RequestEmulator is used to simulate the API requests to the user API. The requests are read from
// the recorded test case of the user app.
// RequestMockHandler defines an interface for implementing hooks that extend and customize
// the behavior of request simulations and test workflows. This interface allows for
// detailed control over various stages of the testing process, including request simulation,
// test status processing, and post-test actions.
type RequestMockHandler interface {
SimulateRequest(ctx context.Context, appID uint64, tc *models.TestCase, testSetID string) (*models.HTTPResp, error)
ProcessTestRunStatus(ctx context.Context, status bool, testSetID string)
Expand Down

0 comments on commit 1f076b4

Please sign in to comment.