diff --git a/go.mod b/go.mod index cd31be9..2605d06 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 06d9aed..924d042 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/main.go b/main.go index 4c5d647..82accca 100644 --- a/main.go +++ b/main.go @@ -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) { @@ -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 @@ -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) { diff --git a/util.go b/util.go index eaddeaf..6f2bf18 100644 --- a/util.go +++ b/util.go @@ -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) + } +}