mirror of
https://github.com/redis/go-redis.git
synced 2026-10-28 08:24:54 +08:00
JSONGetWithArgs appended the paths inside the options != nil block, so with nil options it sent JSON.GET key without the paths and returned the whole document instead of the requested paths.
53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
package redis
|
|
|
|
import (
|
|
"context"
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
// TestJSONGetWithArgsArgs checks that JSONGetWithArgs sends the paths with
|
|
// and without options.
|
|
func TestJSONGetWithArgsArgs(t *testing.T) {
|
|
ctx := context.Background()
|
|
|
|
tests := []struct {
|
|
name string
|
|
options *JSONGetArgs
|
|
paths []string
|
|
want []interface{}
|
|
}{
|
|
{
|
|
name: "nil_options_with_paths",
|
|
paths: []string{"$.a", "$.b"},
|
|
want: []interface{}{"JSON.GET", "key", "$.a", "$.b"},
|
|
},
|
|
{
|
|
name: "nil_options_without_paths",
|
|
want: []interface{}{"JSON.GET", "key"},
|
|
},
|
|
{
|
|
name: "empty_options_with_paths",
|
|
options: &JSONGetArgs{},
|
|
paths: []string{"$.a"},
|
|
want: []interface{}{"JSON.GET", "key", "$.a"},
|
|
},
|
|
{
|
|
name: "options_with_paths",
|
|
options: &JSONGetArgs{Indent: " ", Newline: "\n", Space: " "},
|
|
paths: []string{"$.a"},
|
|
want: []interface{}{"JSON.GET", "key", "INDENT", " ", "NEWLINE", "\n", "SPACE", " ", "$.a"},
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
var captured Cmder
|
|
cmd := captureCmdable(&captured).JSONGetWithArgs(ctx, "key", tt.options, tt.paths...)
|
|
if !reflect.DeepEqual(cmd.Args(), tt.want) {
|
|
t.Errorf("args mismatch\n got: %#v\nwant: %#v", cmd.Args(), tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|