Skip to content

Commit

Permalink
chore: changed sorting logic for test cases
Browse files Browse the repository at this point in the history
Signed-off-by: gouravkrosx <gouravgreatkr@gmail.com>
  • Loading branch information
gouravkrosx committed Apr 23, 2024
1 parent 7e19b14 commit 476280f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.22.1

replace github.com/jackc/pgproto3/v2 => github.com/keploy/pgproto3/v2 v2.0.2

// replace go.keploy.io/server/v2 => /Users/gouravkumar/Desktop/Keploy/Keploy-Server/keploy
replace go.keploy.io/server/v2 => /Users/gouravkumar/Desktop/Keploy/Keploy-Server/keploy

require (
github.com/spf13/viper v1.18.2
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,6 @@ github.com/yudai/pp v2.0.1+incompatible h1:Q4//iY4pNF6yPLZIigmvcl7k/bPgrcTPIFIcm
github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc=
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
go.keploy.io/server/v2 v2.1.0-alpha8 h1:h2HJTUf87+Bnx1dsVi4JrfRSWUpHTVuJbByAJP3S7Sg=
go.keploy.io/server/v2 v2.1.0-alpha8/go.mod h1:rfvNok1h7Oe+MU9DIoCXNnC7WByeK1O4ejReDAZDepE=
go.mongodb.org/mongo-driver v1.11.6 h1:XM7G6PjiGAO5betLF13BIa5TlLUUE3uJ/2Ox3Lz1K+o=
go.mongodb.org/mongo-driver v1.11.6/go.mod h1:G9TgswdsWjX4tmDA5zfs2+6AEPpYJwqblyjsfuh8oXY=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
Expand Down
21 changes: 13 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,9 @@ func compareTestCases(ctx context.Context, logger *zap.Logger, db1, db2 *testdb.
return false
}

// Sort in ascending order of test case name getting in "Keploy-Test-Id"
sort.Slice(readTcs2, func(i, j int) bool {
return readTcs2[i].Name < readTcs2[j].Name
return readTcs2[i].HTTPReq.Header["Keploy-Test-Id"] < readTcs2[j].HTTPReq.Header["Keploy-Test-Id"]
})

if len(readTcs1) != len(readTcs2) {
Expand All @@ -177,13 +178,16 @@ func compareTestCases(ctx context.Context, logger *zap.Logger, db1, db2 *testdb.
ok, req, resp, absRes := replay.AbsMatch(readTcs1[i], readTcs2[i], noiseConfig, true, logger)
if !ok {
logger.Error("Tests are different", zap.String("Pre-recorded", readTcs1[i].Name), zap.String("Test-bench", readTcs2[i].Name))
if !req {
fmt.Printf("HttpReq diff:%v\n", absRes.Req)
}
if !resp {
fmt.Printf("HttpResp diff:%v\n", absRes.Resp)
}

printDiff(!req, "HTTP Request Difference: %v\n", absRes.Req)
printDiff(!resp, "HTTP Response Difference: %v\n", absRes.Resp)
printDiff(!absRes.CurlResult.Normal, "cURL Result Difference: %v\n", absRes.CurlResult)
printDiff(!absRes.Name.Normal, "Test Case Name Difference: %v\n", absRes.Name)

continue
}

printDiff(!absRes.Name.Normal, "Test Case Name Difference: %v\n", absRes.Name)
testSetRes = testSetRes && ok
}
passedOverall = passedOverall && testSetRes
Expand Down Expand Up @@ -216,8 +220,9 @@ func prepareMockAssertion(ctx context.Context, logger *zap.Logger, db1, db2 *tes
return false
}

// Sort in ascending order of test case name getting in "Keploy-Test-Id"
sort.Slice(readTcs2, func(i, j int) bool {
return readTcs2[i].Name < readTcs2[j].Name
return readTcs2[i].HTTPReq.Header["Keploy-Test-Id"] < readTcs2[j].HTTPReq.Header["Keploy-Test-Id"]
})

if len(readTcs1) != len(readTcs2) {
Expand Down
7 changes: 7 additions & 0 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,10 @@ func GetNoiseFromConfig(logger *zap.Logger, configPath string) (*config.Globalno

return &cfg.Test.GlobalNoise, nil
}

// printDiff checks the condition and prints the message if the condition is true
func printDiff(condition bool, message string, value interface{}) {
if condition {
fmt.Printf(message, value)
}
}

0 comments on commit 476280f

Please sign in to comment.