2016-12-12 20:33:28 +03:00
|
|
|
package tests
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
func subTestJSON(t *testing.T, mc *mockServer) {
|
|
|
|
runStep(t, mc, "basic", json_JSET_basic_test)
|
|
|
|
runStep(t, mc, "geojson", json_JSET_geojson_test)
|
2019-10-27 05:33:35 +03:00
|
|
|
runStep(t, mc, "number", json_JSET_number_test)
|
|
|
|
|
2016-12-12 20:33:28 +03:00
|
|
|
}
|
|
|
|
func json_JSET_basic_test(mc *mockServer) error {
|
|
|
|
return mc.DoBatch([][]interface{}{
|
|
|
|
{"JSET", "mykey", "myid1", "hello", "world"}, {"OK"},
|
|
|
|
{"JGET", "mykey", "myid1"}, {`{"hello":"world"}`},
|
|
|
|
{"JSET", "mykey", "myid1", "hello", "planet"}, {"OK"},
|
|
|
|
{"JGET", "mykey", "myid1"}, {`{"hello":"planet"}`},
|
|
|
|
{"JSET", "mykey", "myid1", "user.name.last", "tom"}, {"OK"},
|
|
|
|
{"JSET", "mykey", "myid1", "user.name.first", "andrew"}, {"OK"},
|
2020-09-23 02:43:58 +03:00
|
|
|
{"JGET", "mykey", "myid1"}, {`{"hello":"planet","user":{"name":{"last":"tom","first":"andrew"}}}`},
|
2016-12-12 20:33:28 +03:00
|
|
|
{"JDEL", "mykey", "myid1", "user.name.last"}, {1},
|
2020-09-23 02:43:58 +03:00
|
|
|
{"JGET", "mykey", "myid1"}, {`{"hello":"planet","user":{"name":{"first":"andrew"}}}`},
|
2016-12-12 20:33:28 +03:00
|
|
|
{"JDEL", "mykey", "myid1", "user.name.last"}, {0},
|
2020-09-23 02:43:58 +03:00
|
|
|
{"JGET", "mykey", "myid1"}, {`{"hello":"planet","user":{"name":{"first":"andrew"}}}`},
|
2016-12-12 20:33:28 +03:00
|
|
|
{"JDEL", "mykey2", "myid1", "user.name.last"}, {0},
|
|
|
|
})
|
|
|
|
}
|
2018-10-11 00:25:40 +03:00
|
|
|
|
2016-12-12 20:33:28 +03:00
|
|
|
func json_JSET_geojson_test(mc *mockServer) error {
|
|
|
|
return mc.DoBatch([][]interface{}{
|
|
|
|
{"SET", "mykey", "myid1", "POINT", 33, -115}, {"OK"},
|
|
|
|
{"JGET", "mykey", "myid1"}, {`{"type":"Point","coordinates":[-115,33]}`},
|
|
|
|
{"JSET", "mykey", "myid1", "coordinates.1", 44}, {"OK"},
|
|
|
|
{"JGET", "mykey", "myid1"}, {`{"type":"Point","coordinates":[-115,44]}`},
|
|
|
|
{"SET", "mykey", "myid1", "OBJECT", `{"type":"Feature","geometry":{"type":"Point","coordinates":[-115,44]}}`}, {"OK"},
|
2019-02-12 16:49:13 +03:00
|
|
|
{"JGET", "mykey", "myid1"}, {`{"type":"Feature","geometry":{"type":"Point","coordinates":[-115,44]},"properties":{}}`},
|
2016-12-12 20:33:28 +03:00
|
|
|
{"JGET", "mykey", "myid1", "geometry.type"}, {"Point"},
|
|
|
|
{"JSET", "mykey", "myid1", "properties.tags.-1", "southwest"}, {"OK"},
|
|
|
|
{"JSET", "mykey", "myid1", "properties.tags.-1", "united states"}, {"OK"},
|
|
|
|
{"JSET", "mykey", "myid1", "properties.tags.-1", "hot"}, {"OK"},
|
|
|
|
{"JGET", "mykey", "myid1"}, {`{"type":"Feature","geometry":{"type":"Point","coordinates":[-115,44]},"properties":{"tags":["southwest","united states","hot"]}}`},
|
2018-10-11 00:25:40 +03:00
|
|
|
{"JDEL", "mykey", "myid1", "type"}, {"ERR missing type"},
|
2016-12-12 20:33:28 +03:00
|
|
|
})
|
|
|
|
}
|
2019-10-27 05:33:35 +03:00
|
|
|
|
|
|
|
func json_JSET_number_test(mc *mockServer) error {
|
|
|
|
return mc.DoBatch([][]interface{}{
|
|
|
|
{"JSET", "mykey", "myid1", "hello", "0"}, {"OK"},
|
|
|
|
{"JGET", "mykey", "myid1"}, {`{"hello":0}`},
|
|
|
|
{"JSET", "mykey", "myid1", "hello", "0123"}, {"OK"},
|
|
|
|
{"JGET", "mykey", "myid1"}, {`{"hello":"0123"}`},
|
|
|
|
{"JSET", "mykey", "myid1", "hello", "3.14"}, {"OK"},
|
|
|
|
{"JGET", "mykey", "myid1"}, {`{"hello":3.14}`},
|
|
|
|
{"JSET", "mykey", "myid1", "hello", "1.0e10"}, {"OK"},
|
|
|
|
{"JGET", "mykey", "myid1"}, {`{"hello":1.0e10}`},
|
|
|
|
})
|
2020-09-23 02:43:58 +03:00
|
|
|
}
|