Skip to main content

json_test.go

json_test.go - Overview

This file contains integration tests for JSON operations within the DiceDB database. It tests various JSON functionalities like setting, getting, deleting, and manipulating JSON data.

Detailed Documentation

Type: IntegrationTestCase

type IntegrationTestCase struct {
name string
setupData string
commands []string
expected []interface{}
assertType []string
cleanUp []string
}
  • Purpose: Defines a structure for representing an integration test case. It includes the test name, setup data, commands to execute, expected outputs, assertion types, and cleanup commands.

  • Fields:

    • name: string - The name of the test case.
    • setupData: string - The data to be set up before running the test case.
    • commands: []string - A list of commands to be executed in the test case.
    • expected: []interface{} - A list of expected outputs for the commands.
    • assertType: []string - A list of assertion types corresponding to each command.
    • cleanUp: []string - A list of commands to clean up after the test case.

Function: runIntegrationTests

func runIntegrationTests(t *testing.T, client *dicedb.Client, testCases []IntegrationTestCase, preTestChecksCommand string, postTestChecksCommand string) {
  • Purpose: Executes a series of integration test cases against a DiceDB client.

  • Parameters:

    • t: *testing.T - Testing object for running the tests.
    • client: *dicedb.Client - The DiceDB client to use for testing.
    • testCases: []IntegrationTestCase - A slice of IntegrationTestCase structs, each representing a test case.
    • preTestChecksCommand: string - A DiceDB command to run before each test case.
    • postTestChecksCommand: string - A DiceDB command to run after each test case.
  • Returns: None

Function: TestJSONOperations

func TestJSONOperations(t *testing.T) {
  • Purpose: Tests the basic JSON operations such as JSON.SET and JSON.GET.
  • Parameters:
    • t: *testing.T - Testing object for running the tests.
  • Returns: None

Function: TestJSONSetWithInvalidJSON

func TestJSONSetWithInvalidJSON(t *testing.T) {
  • Purpose: Tests the JSON.SET command with invalid JSON inputs.
  • Parameters:
    • t: *testing.T - Testing object for running the tests.
  • Returns: None

Function: TestUnsupportedJSONPathPatterns

func TestUnsupportedJSONPathPatterns(t *testing.T) {
  • Purpose: Tests scenarios where unsupported JSONPath patterns are used.
  • Parameters:
    • t: *testing.T - Testing object for running the tests.
  • Returns: None

Function: TestJSONSetWithNXAndXX

func TestJSONSetWithNXAndXX(t *testing.T) {
  • Purpose: Tests the JSON.SET command with NX (Not Exists) and XX (Exists) options.
  • Parameters:
    • t: *testing.T - Testing object for running the tests.
  • Returns: None

Function: TestJSONDel

func TestJSONDel(t *testing.T) {
  • Purpose: Tests the JSON.DEL command for deleting JSON values.
  • Parameters:
    • t: *testing.T - Testing object for running the tests.
  • Returns: None

Function: TestJSONMGET

func TestJSONMGET(t *testing.T) {
  • Purpose: Tests the JSON.MGET command for retrieving multiple JSON values.
  • Parameters:
    • t: *testing.T - Testing object for running the tests.
  • Returns: None

Function: sliceContainsItem

func sliceContainsItem(slice []int, item int) bool {
  • Purpose: Checks if an integer slice contains a specific integer item.
  • Parameters:
    • slice: []int - The integer slice to search.
    • item: int - The integer item to search for.
  • Returns: bool - true if the slice contains the item, false otherwise.

Function: testJSONMGETRecursive

func testJSONMGETRecursive(client *dicedb.Client) func(*testing.T) {
  • Purpose: Tests the JSON.MGET command with a recursive JSONPath.
  • Parameters:
    • client: *dicedb.Client - The DiceDB client to use for testing.
  • Returns: func(*testing.T) - A function that takes a testing object as input and performs the test.

Function: TestJSONForget

func TestJSONForget(t *testing.T) {
  • Purpose: Tests the JSON.FORGET command for removing JSON values.
  • Parameters:
    • t: *testing.T - Testing object for running the tests.
  • Returns: None

Function: TestJSONToggle

func TestJSONToggle(t *testing.T) {
  • Purpose: Tests the JSON.TOGGLE command for toggling boolean values in JSON.
  • Parameters:
    • t: *testing.T - Testing object for running the tests.
  • Returns: None

Function: TestJSONNumIncrBy

func TestJSONNumIncrBy(t *testing.T) {
  • Purpose: Tests the JSON.NUMINCRBY command for incrementing numerical values in JSON.
  • Parameters:
    • t: *testing.T - Testing object for running the tests.
  • Returns: None

Function: TestJsonNumMultBy

func TestJsonNumMultBy(t *testing.T) {
  • Purpose: Tests the JSON.NUMMULTBY command for multiplying numerical values in JSON.
  • Parameters:
    • t: *testing.T - Testing object for running the tests.
  • Returns: None

Function: TestJsonStrlen

func TestJsonStrlen(t *testing.T) {
  • Purpose: Tests the JSON.STRLEN command for getting the length of string values in JSON.
  • Parameters:
    • t: *testing.T - Testing object for running the tests.
  • Returns: None

Function: TestJsonSTRAPPEND

func TestJsonSTRAPPEND(t *testing.T) {
  • Purpose: Tests the JSON.STRAPPEND command for appending strings to string values in JSON.
  • Parameters:
    • t: *testing.T - Testing object for running the tests.
  • Returns: None

Function: TestJSONClearOperations

func TestJSONClearOperations(t *testing.T) {
  • Purpose: Tests the JSON.CLEAR command for clearing JSON values.
  • Parameters:
    • t: *testing.T - Testing object for running the tests.
  • Returns: None

Function: TestJsonObjLen

func TestJsonObjLen(t *testing.T) {
  • Purpose: Tests the JSON.OBJLEN command for getting the length of JSON objects.
  • Parameters:
    • t: *testing.T - Testing object for running the tests.
  • Returns: None

Function: TestJSONARRPOP

func TestJSONARRPOP(t *testing.T) {
  • Purpose: Tests the JSON.ARRPOP command for removing elements from a JSON array.
  • Parameters:
    • t: *testing.T - Testing object for running the tests.
  • Returns: None

Function: TestJsonARRAPPEND

func TestJsonARRAPPEND(t *testing.T) {
  • Purpose: Tests the JSON.ARRAPPEND command for appending elements to a JSON array.
  • Parameters:
    • t: *testing.T - Testing object for running the tests.
  • Returns: None

Function: TestJsonARRINSERT

func TestJsonARRINSERT(t *testing.T) {
  • Purpose: Tests the JSON.ARRINSERT command for inserting elements into a JSON array.
  • Parameters:
    • t: *testing.T - Testing object for running the tests.
  • Returns: None

Function: TestJsonObjKeys

func TestJsonObjKeys(t *testing.T) {
  • Purpose: Tests the JSON.OBJKEYS command for retrieving the keys of a JSON object.
  • Parameters:
    • t: *testing.T - Testing object for running the tests.
  • Returns: None

Function: sortNestedSlices

func sortNestedSlices(data []interface{}) []interface{} {
  • Purpose: Sorts nested slices within a slice of interfaces.
  • Parameters:
    • data: []interface{} - The slice of interfaces containing potentially nested slices.
  • Returns: []interface{} - A new slice with nested slices sorted.

Function: TestJsonARRTRIM

func TestJsonARRTRIM(t *testing.T) {
  • Purpose: Tests the JSON.ARRTRIM command for trimming a JSON array.
  • Parameters:
    • t: *testing.T - Testing object for running the tests.
  • Returns: None

Function: TestJSONARRINDEX

func TestJSONARRINDEX(t *testing.T) {
  • Purpose: Tests the JSON.ARRINDEX command for searching for an element in a JSON array and returning its index.
  • Parameters:
    • t: *testing.T - Testing object for running the tests.
  • Returns: None

Getting Started Relevance