diff options
author | Christopher Speller <crspeller@gmail.com> | 2015-11-26 09:02:00 -0500 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2015-11-26 09:02:00 -0500 |
commit | 006fc61ecce1ba3d5c7b7163309467c24edbbc46 (patch) | |
tree | 533f5dcd094ebd94d425e64a4261b7b21ec6f3fa /Godeps/_workspace/src/github.com/garyburd/redigo/redis/scan_test.go | |
parent | aaced173f8b3020fbbef236d84b070c2c67ee968 (diff) | |
parent | 2639452967e66c4840164c36817234d3e7c12ac1 (diff) | |
download | chat-006fc61ecce1ba3d5c7b7163309467c24edbbc46.tar.gz chat-006fc61ecce1ba3d5c7b7163309467c24edbbc46.tar.bz2 chat-006fc61ecce1ba3d5c7b7163309467c24edbbc46.zip |
Merge pull request #1505 from mattermost/lib-upgrade
Lib upgrade
Diffstat (limited to 'Godeps/_workspace/src/github.com/garyburd/redigo/redis/scan_test.go')
-rw-r--r-- | Godeps/_workspace/src/github.com/garyburd/redigo/redis/scan_test.go | 64 |
1 files changed, 46 insertions, 18 deletions
diff --git a/Godeps/_workspace/src/github.com/garyburd/redigo/redis/scan_test.go b/Godeps/_workspace/src/github.com/garyburd/redigo/redis/scan_test.go index b57dd8969..d364dff42 100644 --- a/Godeps/_workspace/src/github.com/garyburd/redigo/redis/scan_test.go +++ b/Godeps/_workspace/src/github.com/garyburd/redigo/redis/scan_test.go @@ -16,10 +16,11 @@ package redis_test import ( "fmt" - "github.com/garyburd/redigo/redis" "math" "reflect" "testing" + + "github.com/garyburd/redigo/redis" ) var scanConversionTests = []struct { @@ -46,6 +47,7 @@ var scanConversionTests = []struct { {[]byte("1"), true}, {int64(1), true}, {[]byte("t"), true}, + {"hello", "hello"}, {[]byte("hello"), "hello"}, {[]byte("world"), []byte("world")}, {[]interface{}{[]byte("foo")}, []interface{}{[]byte("foo")}}, @@ -100,7 +102,8 @@ func TestScanConversionError(t *testing.T) { func ExampleScan() { c, err := dial() if err != nil { - panic(err) + fmt.Println(err) + return } defer c.Close() @@ -115,7 +118,8 @@ func ExampleScan() { "GET", "album:*->title", "GET", "album:*->rating")) if err != nil { - panic(err) + fmt.Println(err) + return } for len(values) > 0 { @@ -123,7 +127,8 @@ func ExampleScan() { rating := -1 // initialize to illegal value to detect nil. values, err = redis.Scan(values, &title, &rating) if err != nil { - panic(err) + fmt.Println(err) + return } if rating == -1 { fmt.Println(title, "not-rated") @@ -295,7 +300,8 @@ func TestScanSlice(t *testing.T) { func ExampleScanSlice() { c, err := dial() if err != nil { - panic(err) + fmt.Println(err) + return } defer c.Close() @@ -310,7 +316,8 @@ func ExampleScanSlice() { "GET", "album:*->title", "GET", "album:*->rating")) if err != nil { - panic(err) + fmt.Println(err) + return } var albums []struct { @@ -318,7 +325,8 @@ func ExampleScanSlice() { Rating int } if err := redis.ScanSlice(values, &albums); err != nil { - panic(err) + fmt.Println(err) + return } fmt.Printf("%v\n", albums) // Output: @@ -332,16 +340,17 @@ var argsTests = []struct { }{ {"struct ptr", redis.Args{}.AddFlat(&struct { - I int `redis:"i"` - U uint `redis:"u"` - S string `redis:"s"` - P []byte `redis:"p"` + I int `redis:"i"` + U uint `redis:"u"` + S string `redis:"s"` + P []byte `redis:"p"` + M map[string]string `redis:"m"` Bt bool Bf bool }{ - -1234, 5678, "hello", []byte("world"), true, false, + -1234, 5678, "hello", []byte("world"), map[string]string{"hello": "world"}, true, false, }), - redis.Args{"i", int(-1234), "u", uint(5678), "s", "hello", "p", []byte("world"), "Bt", true, "Bf", false}, + redis.Args{"i", int(-1234), "u", uint(5678), "s", "hello", "p", []byte("world"), "m", map[string]string{"hello": "world"}, "Bt", true, "Bf", false}, }, {"struct", redis.Args{}.AddFlat(struct{ I int }{123}), @@ -351,6 +360,20 @@ var argsTests = []struct { redis.Args{}.Add(1).AddFlat([]string{"a", "b", "c"}).Add(2), redis.Args{1, "a", "b", "c", 2}, }, + {"struct omitempty", + redis.Args{}.AddFlat(&struct { + I int `redis:"i,omitempty"` + U uint `redis:"u,omitempty"` + S string `redis:"s,omitempty"` + P []byte `redis:"p,omitempty"` + M map[string]string `redis:"m,omitempty"` + Bt bool `redis:"Bt,omitempty"` + Bf bool `redis:"Bf,omitempty"` + }{ + 0, 0, "", []byte{}, map[string]string{}, true, false, + }), + redis.Args{"Bt", true}, + }, } func TestArgs(t *testing.T) { @@ -364,7 +387,8 @@ func TestArgs(t *testing.T) { func ExampleArgs() { c, err := dial() if err != nil { - panic(err) + fmt.Println(err) + return } defer c.Close() @@ -379,7 +403,8 @@ func ExampleArgs() { p1.Body = "Hello" if _, err := c.Do("HMSET", redis.Args{}.Add("id1").AddFlat(&p1)...); err != nil { - panic(err) + fmt.Println(err) + return } m := map[string]string{ @@ -389,18 +414,21 @@ func ExampleArgs() { } if _, err := c.Do("HMSET", redis.Args{}.Add("id2").AddFlat(m)...); err != nil { - panic(err) + fmt.Println(err) + return } for _, id := range []string{"id1", "id2"} { v, err := redis.Values(c.Do("HGETALL", id)) if err != nil { - panic(err) + fmt.Println(err) + return } if err := redis.ScanStruct(v, &p2); err != nil { - panic(err) + fmt.Println(err) + return } fmt.Printf("%+v\n", p2) |