diff --git a/integration_tests/commands/http/json_test.go b/integration_tests/commands/http/json_test.go index 0621ae5f6..b2c9fe6f3 100644 --- a/integration_tests/commands/http/json_test.go +++ b/integration_tests/commands/http/json_test.go @@ -8,8 +8,7 @@ import ( "testing" "github.com/dicedb/dice/testutils" - testifyAssert "github.com/stretchr/testify/assert" - "gotest.tools/v3/assert" + "github.com/stretchr/testify/assert" ) type IntegrationTestCase struct { @@ -59,11 +58,11 @@ func runIntegrationTests(t *testing.T, exec *HTTPCommandExecutor, testCases []In case "equal": assert.Equal(t, out, result) case "perm_equal": - assert.Assert(t, testutils.ArraysArePermutations(testutils.ConvertToArray(out.(string)), testutils.ConvertToArray(result.(string)))) + assert.True(t, testutils.ArraysArePermutations(testutils.ConvertToArray(out.(string)), testutils.ConvertToArray(result.(string)))) case "range": - assert.Assert(t, result.(float64) <= out.(float64) && result.(float64) > 0, "Expected %v to be within 0 to %v", result, out) + assert.True(t, result.(float64) <= out.(float64) && result.(float64) > 0, "Expected %v to be within 0 to %v", result, out) case "json_equal": - testifyAssert.JSONEq(t, out.(string), result.(string)) + assert.JSONEq(t, out.(string), result.(string)) } } }) @@ -250,7 +249,7 @@ func TestJSONOperations(t *testing.T) { result, _ := exec.FireCommand(cmd) if jsonResult, ok := result.(string); ok && testutils.IsJSONResponse(jsonResult) { - testifyAssert.JSONEq(t, tc.expected[i].(string), jsonResult) + assert.JSONEq(t, tc.expected[i].(string), jsonResult) } else { assert.Equal(t, tc.expected[i], result) } @@ -268,7 +267,7 @@ func TestJSONOperations(t *testing.T) { if jsonResult, ok := result.(string); ok && testutils.IsJSONResponse(jsonResult) { var jsonPayload []interface{} json.Unmarshal([]byte(jsonResult), &jsonPayload) - assert.Assert(t, testutils.UnorderedEqual(tc.expected[i], jsonPayload)) + assert.True(t, testutils.UnorderedEqual(tc.expected[i], jsonPayload)) } else { assert.Equal(t, tc.expected[i], result) } @@ -309,7 +308,7 @@ func TestJSONSetWithInvalidCases(t *testing.T) { t.Run(tc.name, func(t *testing.T) { for i, cmd := range tc.commands { result, _ := exec.FireCommand(cmd) - assert.Assert(t, strings.HasPrefix(result.(string), tc.expected[i].(string)), fmt.Sprintf("Expected: %s, Got: %s", tc.expected[i], result)) + assert.True(t, strings.HasPrefix(result.(string), tc.expected[i].(string)), fmt.Sprintf("Expected: %s, Got: %s", tc.expected[i], result)) } }) } @@ -377,7 +376,7 @@ func TestJSONSetWithNXAndXX(t *testing.T) { result, _ := exec.FireCommand(cmd) jsonResult, isString := result.(string) if isString && testutils.IsJSONResponse(jsonResult) { - testifyAssert.JSONEq(t, tc.expected[i].(string), jsonResult) + assert.JSONEq(t, tc.expected[i].(string), jsonResult) } else { assert.Equal(t, tc.expected[i], result) } @@ -869,7 +868,7 @@ func TestJsonStrlen(t *testing.T) { if stringResult, ok := result.(string); ok { assert.Equal(t, tc.expected[i], stringResult) } else { - assert.Assert(t, testutils.UnorderedEqual(tc.expected[i], result.([]interface{}))) + assert.True(t, testutils.UnorderedEqual(tc.expected[i], result.([]interface{}))) } } }) @@ -960,7 +959,7 @@ func TestJSONMGET(t *testing.T) { resultStr, resultIsString := resultVal.(string) if isString && resultIsString && testutils.IsJSONResponse(expectedStr) { - testifyAssert.JSONEq(t, expectedStr, resultStr) + assert.JSONEq(t, expectedStr, resultStr) } else { assert.Equal(t, expectedVal, resultVal) } @@ -976,7 +975,7 @@ func TestJSONMGET(t *testing.T) { t.Run("MGET with recursive path", func(t *testing.T) { result, _ := exec.FireCommand(HTTPCommand{Command: "JSON.MGET", Body: map[string]interface{}{"keys": []interface{}{"doc1", "doc2"}, "path": "$..a"}}) results, ok := result.([]interface{}) - assert.Assert(t, ok, "Expected result to be a slice of interface{}") + assert.True(t, ok, "Expected result to be a slice of interface{}") expectedResults := [][]int{{1, 3}, {4, 6}} assert.Equal(t, len(expectedResults), len(results), "Expected 2 results") @@ -1052,9 +1051,9 @@ func TestJsonARRAPPEND(t *testing.T) { // because the order of keys is not guaranteed, we need to check if the result is an array if slice, ok := tc.expected[i].([]interface{}); ok { - assert.Assert(t, testutils.UnorderedEqual(slice, result)) + assert.True(t, testutils.UnorderedEqual(slice, result)) } else if testutils.IsJSONResponse(tc.expected[i].(string)) { - testifyAssert.JSONEq(t, tc.expected[i].(string), result.(string)) + assert.JSONEq(t, tc.expected[i].(string), result.(string)) } else { assert.Equal(t, tc.expected[i], result) } @@ -1302,7 +1301,7 @@ func TestJsonObjLen(t *testing.T) { result, _ := exec.FireCommand(cmd) if slice, ok := tc.expected[i].([]interface{}); ok { - assert.Assert(t, testutils.UnorderedEqual(slice, result)) + assert.True(t, testutils.UnorderedEqual(slice, result)) } else { assert.Equal(t, tc.expected[i], result) } @@ -1493,9 +1492,9 @@ func TestJsonARRINSERT(t *testing.T) { // because the order of keys is not guaranteed, we need to check if the result is an array if slice, ok := tc.expected[i].([]interface{}); ok { - assert.Assert(t, testutils.UnorderedEqual(slice, result)) + assert.True(t, testutils.UnorderedEqual(slice, result)) } else if testutils.IsJSONResponse(tc.expected[i].(string)) { - testifyAssert.JSONEq(t, tc.expected[i].(string), result.(string)) + assert.JSONEq(t, tc.expected[i].(string), result.(string)) } else { assert.Equal(t, tc.expected[i], result) } @@ -1633,11 +1632,11 @@ func TestJsonObjKeys(t *testing.T) { if tc.assertType[i] == "equal" { assert.Equal(t, out, result) } else if tc.assertType[i] == "perm_equal" { - assert.Assert(t, testutils.ArraysArePermutations(out.([]interface{}), result.([]interface{}))) + assert.True(t, testutils.ArraysArePermutations(out.([]interface{}), result.([]interface{}))) } else if tc.assertType[i] == "json_equal" { - testifyAssert.JSONEq(t, out.(string), result.(string)) + assert.JSONEq(t, out.(string), result.(string)) } else if tc.assertType[i] == "nested_perm_equal" { - testifyAssert.ElementsMatch(t, + assert.ElementsMatch(t, sortNestedSlices(out.([]interface{})), sortNestedSlices(result.([]interface{})), "Mismatch in JSON object keys", @@ -1757,9 +1756,9 @@ func TestJsonARRTRIM(t *testing.T) { result, _ := exec.FireCommand(cmd) if slice, ok := tc.expected[i].([]interface{}); ok { - assert.Assert(t, testutils.UnorderedEqual(slice, result)) + assert.True(t, testutils.UnorderedEqual(slice, result)) } else if testutils.IsJSONResponse(tc.expected[i].(string)) { - testifyAssert.JSONEq(t, tc.expected[i].(string), result.(string)) + assert.JSONEq(t, tc.expected[i].(string), result.(string)) } else { assert.Equal(t, tc.expected[i], result) } diff --git a/integration_tests/commands/resp/getwatch_test.go b/integration_tests/commands/resp/getwatch_test.go index da5fa9042..38246e98f 100644 --- a/integration_tests/commands/resp/getwatch_test.go +++ b/integration_tests/commands/resp/getwatch_test.go @@ -114,9 +114,9 @@ func TestGETWATCHWithSDK(t *testing.T) { for _, channel := range channels { v := <-channel - assert.Equal(t, "GET", v.Command) // command + assert.Equal(t, "GET", v.Command) // command assert.Equal(t, "2714318480", v.Fingerprint) // Fingerprint - assert.Equal(t, tc.val, v.Data.(string)) // data + assert.Equal(t, tc.val, v.Data.(string)) // data } } } @@ -145,9 +145,9 @@ func TestGETWATCHWithSDK2(t *testing.T) { for _, channel := range channels { v := <-channel - assert.Equal(t, "GET", v.Command) // command + assert.Equal(t, "GET", v.Command) // command assert.Equal(t, "2714318480", v.Fingerprint) // Fingerprint - assert.Equal(t, tc.val, v.Data.(string)) // data + assert.Equal(t, tc.val, v.Data.(string)) // data } } } diff --git a/integration_tests/commands/resp/json_test.go b/integration_tests/commands/resp/json_test.go index 434b36cfd..a2a9e9c70 100644 --- a/integration_tests/commands/resp/json_test.go +++ b/integration_tests/commands/resp/json_test.go @@ -7,9 +7,8 @@ import ( "testing" "github.com/dicedb/dice/testutils" - "gotest.tools/v3/assert" - testifyAssert "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/assert" ) type IntegrationTestCase struct { @@ -55,11 +54,11 @@ func runIntegrationTests(t *testing.T, conn net.Conn, testCases []IntegrationTes case "equal": assert.Equal(t, out, result) case "perm_equal": - assert.Assert(t, testutils.ArraysArePermutations(testutils.ConvertToArray(out.(string)), testutils.ConvertToArray(result.(string)))) + assert.True(t, testutils.ArraysArePermutations(testutils.ConvertToArray(out.(string)), testutils.ConvertToArray(result.(string)))) case "range": - assert.Assert(t, result.(int64) <= out.(int64) && result.(int64) > 0, "Expected %v to be within 0 to %v", result, out) + assert.True(t, result.(int64) <= out.(int64) && result.(int64) > 0, "Expected %v to be within 0 to %v", result, out) case "json_equal": - testifyAssert.JSONEq(t, out.(string), result.(string)) + assert.JSONEq(t, out.(string), result.(string)) } } }) @@ -539,7 +538,7 @@ func TestJsonStrlen(t *testing.T) { if ok { assert.Equal(t, tc.expected[i], stringResult) } else { - assert.Assert(t, testutils.ArraysArePermutations(tc.expected[i].([]interface{}), result.([]interface{}))) + assert.True(t, testutils.ArraysArePermutations(tc.expected[i].([]interface{}), result.([]interface{}))) } } }) @@ -743,7 +742,7 @@ func TestJsonObjLen(t *testing.T) { cmd := tcase.commands[i] out := tcase.expected[i] result := FireCommand(conn, cmd) - assert.DeepEqual(t, out, result) + assert.Equal(t, out, result, "Expected out and result to be deeply equal") } }) } @@ -790,14 +789,14 @@ func TestJSONARRPOP(t *testing.T) { jsonResult, isString := result.(string) if isString && testutils.IsJSONResponse(jsonResult) { - testifyAssert.JSONEq(t, out.(string), jsonResult) + assert.JSONEq(t, out.(string), jsonResult) continue } if tcase.assertType[i] == "equal" { assert.Equal(t, out, result) } else if tcase.assertType[i] == "deep_equal" { - assert.Assert(t, testutils.ArraysArePermutations(out.([]interface{}), result.([]interface{}))) + assert.True(t, testutils.ArraysArePermutations(out.([]interface{}), result.([]interface{}))) } } }) @@ -854,7 +853,7 @@ func TestJsonARRAPPEND(t *testing.T) { if tcase.assertType[i] == "equal" { assert.Equal(t, out, result) } else if tcase.assertType[i] == "deep_equal" { - assert.Assert(t, testutils.ArraysArePermutations(out.([]interface{}), result.([]interface{}))) + assert.True(t, testutils.ArraysArePermutations(out.([]interface{}), result.([]interface{}))) } } }) @@ -926,9 +925,9 @@ func TestJsonARRINSERT(t *testing.T) { if tcase.assertType[i] == "equal" { assert.Equal(t, out, result) } else if tcase.assertType[i] == "deep_equal" { - assert.Assert(t, testutils.ArraysArePermutations(out.([]interface{}), result.([]interface{}))) + assert.True(t, testutils.ArraysArePermutations(out.([]interface{}), result.([]interface{}))) } else if tcase.assertType[i] == "jsoneq" { - testifyAssert.JSONEq(t, out.(string), result.(string)) + assert.JSONEq(t, out.(string), result.(string)) } } }) @@ -1044,11 +1043,11 @@ func TestJsonObjKeys(t *testing.T) { if tc.assertType[i] == "equal" { assert.Equal(t, out, result) } else if tc.assertType[i] == "perm_equal" { - assert.Assert(t, testutils.ArraysArePermutations(out.([]interface{}), result.([]interface{}))) + assert.True(t, testutils.ArraysArePermutations(out.([]interface{}), result.([]interface{}))) } else if tc.assertType[i] == "json_equal" { - testifyAssert.JSONEq(t, out.(string), result.(string)) + assert.JSONEq(t, out.(string), result.(string)) } else if tc.assertType[i] == "nested_perm_equal" { - testifyAssert.ElementsMatch(t, + assert.ElementsMatch(t, sortNestedSlices(out.([]interface{})), sortNestedSlices(result.([]interface{})), "Mismatch in JSON object keys", @@ -1151,9 +1150,9 @@ func TestJsonARRTRIM(t *testing.T) { if tcase.assertType[i] == "equal" { assert.Equal(t, out, result) } else if tcase.assertType[i] == "deep_equal" { - assert.Assert(t, testutils.ArraysArePermutations(out.([]interface{}), result.([]interface{}))) + assert.True(t, testutils.ArraysArePermutations(out.([]interface{}), result.([]interface{}))) } else if tcase.assertType[i] == "jsoneq" { - testifyAssert.JSONEq(t, out.(string), result.(string)) + assert.JSONEq(t, out.(string), result.(string)) } } }) diff --git a/integration_tests/commands/websocket/json_test.go b/integration_tests/commands/websocket/json_test.go index a1c8f186d..75ba0b269 100644 --- a/integration_tests/commands/websocket/json_test.go +++ b/integration_tests/commands/websocket/json_test.go @@ -7,9 +7,7 @@ import ( "github.com/dicedb/dice/testutils" "github.com/gorilla/websocket" - testifyAssert "github.com/stretchr/testify/assert" - - "gotest.tools/v3/assert" + "github.com/stretchr/testify/assert" ) type IntegrationTestCase struct { @@ -50,17 +48,16 @@ func runIntegrationTests(t *testing.T, exec *WebsocketCommandExecutor, conn *web cmd := tc.commands[i] out := tc.expected[i] result, _ := exec.FireCommandAndReadResponse(conn, cmd) - fmt.Println(result, out, 53) switch tc.assertType[i] { case "equal": assert.Equal(t, out, result) case "perm_equal": - assert.Assert(t, testutils.ArraysArePermutations(testutils.ConvertToArray(out.(string)), testutils.ConvertToArray(result.(string)))) + assert.True(t, testutils.ArraysArePermutations(testutils.ConvertToArray(out.(string)), testutils.ConvertToArray(result.(string)))) case "range": - assert.Assert(t, result.(float64) <= out.(float64) && result.(float64) > 0, "Expected %v to be within 0 to %v", result, out) + assert.True(t, result.(float64) <= out.(float64) && result.(float64) > 0, "Expected %v to be within 0 to %v", result, out) case "json_equal": - testifyAssert.JSONEq(t, out.(string), result.(string)) + assert.JSONEq(t, out.(string), result.(string)) } } }) @@ -76,7 +73,7 @@ func TestJSONClearOperations(t *testing.T) { defer func() { resp, err := exec.FireCommandAndReadResponse(conn, "DEL user") - testifyAssert.Nil(t, err) + assert.Nil(t, err) assert.Equal(t, float64(1), resp) }() @@ -150,7 +147,7 @@ func TestJSONClearOperations(t *testing.T) { t.Run(tc.name, func(t *testing.T) { for i, cmd := range tc.commands { result, err := exec.FireCommandAndReadResponse(conn, cmd) - testifyAssert.Nil(t, err) + assert.Nil(t, err) assert.Equal(t, tc.expected[i], result) } }) @@ -167,7 +164,7 @@ func TestJsonStrlen(t *testing.T) { defer func() { resp, err := exec.FireCommandAndReadResponse(conn, "DEL doc") - testifyAssert.Nil(t, err) + assert.Nil(t, err) assert.Equal(t, float64(1), resp) }() @@ -238,12 +235,12 @@ func TestJsonStrlen(t *testing.T) { t.Run(tc.name, func(t *testing.T) { for i, cmd := range tc.commands { result, err := exec.FireCommandAndReadResponse(conn, cmd) - testifyAssert.Nil(t, err, "error: %v", err) + assert.Nil(t, err, "error: %v", err) stringResult, ok := result.(string) if ok { assert.Equal(t, tc.expected[i], stringResult) } else { - assert.Assert(t, testutils.ArraysArePermutations(tc.expected[i].([]interface{}), result.([]interface{}))) + assert.True(t, testutils.ArraysArePermutations(tc.expected[i].([]interface{}), result.([]interface{}))) } } }) @@ -264,7 +261,7 @@ func TestJsonObjLen(t *testing.T) { defer func() { resp, err := exec.FireCommandAndReadResponse(conn, "DEL obj") - testifyAssert.Nil(t, err) + assert.Nil(t, err) assert.Equal(t, float64(1), resp) }() @@ -367,8 +364,8 @@ func TestJsonObjLen(t *testing.T) { cmd := tcase.commands[i] out := tcase.expected[i] result, err := exec.FireCommandAndReadResponse(conn, cmd) - testifyAssert.Nil(t, err) - assert.DeepEqual(t, out, result) + assert.Nil(t, err) + assert.Equal(t, out, result) } }) } @@ -385,7 +382,7 @@ func TestJsonARRTRIM(t *testing.T) { defer func() { resp1, err := exec.FireCommandAndReadResponse(conn, "DEL a") resp2, err := exec.FireCommandAndReadResponse(conn, "DEL b") - testifyAssert.Nil(t, err) + assert.Nil(t, err) assert.Equal(t, float64(1), resp1) assert.Equal(t, float64(1), resp2) }() @@ -452,13 +449,13 @@ func TestJsonARRTRIM(t *testing.T) { cmd := tcase.commands[i] out := tcase.expected[i] result, err := exec.FireCommandAndReadResponse(conn, cmd) - testifyAssert.Nil(t, err) + assert.Nil(t, err) if tcase.assertType[i] == "equal" { assert.Equal(t, out, result) } else if tcase.assertType[i] == "deep_equal" { - assert.Assert(t, testutils.ArraysArePermutations(out.([]interface{}), result.([]interface{}))) + assert.True(t, testutils.ArraysArePermutations(out.([]interface{}), result.([]interface{}))) } else if tcase.assertType[i] == "jsoneq" { - testifyAssert.JSONEq(t, out.(string), result.(string)) + assert.JSONEq(t, out.(string), result.(string)) } } }) @@ -476,7 +473,7 @@ func TestJsonARRINSERT(t *testing.T) { defer func() { resp1, err := exec.FireCommandAndReadResponse(conn, "DEL a") resp2, err := exec.FireCommandAndReadResponse(conn, "DEL b") - testifyAssert.Nil(t, err) + assert.Nil(t, err) assert.Equal(t, float64(1), resp1) assert.Equal(t, float64(1), resp2) }() @@ -531,14 +528,13 @@ func TestJsonARRINSERT(t *testing.T) { cmd := tcase.commands[i] out := tcase.expected[i] result, err := exec.FireCommandAndReadResponse(conn, cmd) - fmt.Println(result, out, err) - testifyAssert.Nil(t, err) + assert.Nil(t, err) if tcase.assertType[i] == "equal" { assert.Equal(t, out, result) } else if tcase.assertType[i] == "deep_equal" { - assert.Assert(t, testutils.ArraysArePermutations(out.([]interface{}), result.([]interface{}))) + assert.True(t, testutils.ArraysArePermutations(out.([]interface{}), result.([]interface{}))) } else if tcase.assertType[i] == "jsoneq" { - testifyAssert.JSONEq(t, out.(string), result.(string)) + assert.JSONEq(t, out.(string), result.(string)) } } }) @@ -642,7 +638,7 @@ func TestJsonObjKeyslmao(t *testing.T) { for _, tcase := range testCases { t.Run(tcase.name, func(t *testing.T) { _, err := exec.FireCommandAndReadResponse(conn, tcase.setCommand) - testifyAssert.Nil(t, err) + assert.Nil(t, err) expected := tcase.expected out, _ := exec.FireCommandAndReadResponse(conn, tcase.testCommand) @@ -661,10 +657,10 @@ func TestJsonObjKeyslmao(t *testing.T) { } if outSlice, ok := out.([]interface{}); ok { sortNested(outSlice) - testifyAssert.ElementsMatch(t, expected, outSlice) + assert.ElementsMatch(t, expected, outSlice) } else { outInterface := []interface{}{out} - testifyAssert.ElementsMatch(t, expected, outInterface) + assert.ElementsMatch(t, expected, outInterface) } }) } @@ -709,18 +705,18 @@ func TestJSONARRPOP(t *testing.T) { cmd := tcase.commands[i] out := tcase.expected[i] result, err := exec.FireCommandAndReadResponse(conn, cmd) - testifyAssert.Nil(t, err) + assert.Nil(t, err) jsonResult, isString := result.(string) if isString && testutils.IsJSONResponse(jsonResult) { - testifyAssert.JSONEq(t, out.(string), jsonResult) + assert.JSONEq(t, out.(string), jsonResult) continue } if tcase.assertType[i] == "equal" { assert.Equal(t, out, result) } else if tcase.assertType[i] == "deep_equal" { - assert.Assert(t, testutils.ArraysArePermutations(tcase.expected[i].([]interface{}), result.([]interface{}))) + assert.True(t, testutils.ArraysArePermutations(tcase.expected[i].([]interface{}), result.([]interface{}))) } } }) @@ -777,18 +773,18 @@ func TestJsonARRAPPEND(t *testing.T) { cmd := tcase.commands[i] out := tcase.expected[i] result, err := exec.FireCommandAndReadResponse(conn, cmd) - testifyAssert.Nil(t, err) + assert.Nil(t, err) jsonResult, isString := result.(string) if isString && testutils.IsJSONResponse(jsonResult) { - testifyAssert.JSONEq(t, out.(string), jsonResult) + assert.JSONEq(t, out.(string), jsonResult) continue } if tcase.assertType[i] == "equal" { assert.Equal(t, out, result) } else if tcase.assertType[i] == "deep_equal" { - assert.Assert(t, testutils.ArraysArePermutations(tcase.expected[i].([]interface{}), result.([]interface{}))) + assert.True(t, testutils.ArraysArePermutations(tcase.expected[i].([]interface{}), result.([]interface{}))) } } })