ledisdb/server/cmd_script_test.go

61 lines
1.7 KiB
Go
Raw Permalink Normal View History

// +build lua
2014-09-02 13:55:12 +04:00
package server
import (
"fmt"
"reflect"
"testing"
2015-05-04 17:42:28 +03:00
"github.com/siddontang/goredis"
2014-09-02 13:55:12 +04:00
)
func TestCmdEval(t *testing.T) {
c := getTestConn()
defer c.Close()
2015-03-11 06:54:02 +03:00
if v, err := goredis.Strings(c.Do("eval", "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", 2, "key1", "key2", "first", "second")); err != nil {
2014-09-02 13:55:12 +04:00
t.Fatal(err)
} else if !reflect.DeepEqual(v, []string{"key1", "key2", "first", "second"}) {
t.Fatal(fmt.Sprintf("%v", v))
}
2015-03-11 06:54:02 +03:00
if v, err := goredis.Strings(c.Do("eval", "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", 2, "key1", "key2", "first", "second")); err != nil {
2014-09-02 13:55:12 +04:00
t.Fatal(err)
2014-09-02 18:04:18 +04:00
} else if !reflect.DeepEqual(v, []string{"key1", "key2", "first", "second"}) {
t.Fatal(fmt.Sprintf("%v", v))
}
var sha1 string
var err error
2015-03-11 06:54:02 +03:00
if sha1, err = goredis.String(c.Do("script", "load", "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}")); err != nil {
2014-09-02 18:04:18 +04:00
t.Fatal(err)
} else if len(sha1) != 40 {
t.Fatal(sha1)
}
2015-03-11 06:54:02 +03:00
if v, err := goredis.Strings(c.Do("evalsha", sha1, 2, "key1", "key2", "first", "second")); err != nil {
2014-09-02 13:55:12 +04:00
t.Fatal(err)
} else if !reflect.DeepEqual(v, []string{"key1", "key2", "first", "second"}) {
t.Fatal(fmt.Sprintf("%v", v))
}
2014-09-02 18:04:18 +04:00
2015-03-11 06:54:02 +03:00
if ay, err := goredis.Values(c.Do("script", "exists", sha1, "01234567890123456789")); err != nil {
2014-09-02 18:04:18 +04:00
t.Fatal(err)
} else if !reflect.DeepEqual(ay, []interface{}{int64(1), int64(0)}) {
t.Fatal(fmt.Sprintf("%v", ay))
}
2015-03-11 06:54:02 +03:00
if ok, err := goredis.String(c.Do("script", "flush")); err != nil {
2014-09-02 18:04:18 +04:00
t.Fatal(err)
} else if ok != "OK" {
t.Fatal(ok)
}
2015-03-11 06:54:02 +03:00
if ay, err := goredis.Values(c.Do("script", "exists", sha1)); err != nil {
2014-09-02 18:04:18 +04:00
t.Fatal(err)
} else if !reflect.DeepEqual(ay, []interface{}{int64(0)}) {
t.Fatal(fmt.Sprintf("%v", ay))
}
2014-09-02 13:55:12 +04:00
}