本文整理汇总了Golang中github.com/rafaeljusto/redigomock.NewConn函数的典型用法代码示例。如果您正苦于以下问题:Golang NewConn函数的具体用法?Golang NewConn怎么用?Golang NewConn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewConn函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestUpdateRedisMapReferenceRedisErrors
func TestUpdateRedisMapReferenceRedisErrors(t *testing.T) {
// should return error if redis does
redigomock.Clear()
redigomock.Command("GETSET", "map", "map:1").ExpectError(errors.New("redis error"))
err := UpdateRedisMapReference(redigomock.NewConn(),
Params{},
MapConfig{
Name: "map",
HashKey: "map:1",
},
)
assert.EqualError(t, err, "redis error")
redigomock.Clear()
redigomock.Command("GETSET", "map", "map:1").Expect("map:0")
redigomock.Command("DEL", "map:0").ExpectError(errors.New("redis error"))
err = UpdateRedisMapReference(redigomock.NewConn(),
Params{},
MapConfig{
Name: "map",
HashKey: "map:1",
},
)
assert.EqualError(t, err, "redis error")
}
开发者ID:bgveenstra,项目名称:moredis,代码行数:26,代码来源:moredis_test.go
示例2: Test_StringStorage_WalkKeys_CloseDirectly
func Test_StringStorage_WalkKeys_CloseDirectly(t *testing.T) {
c := redigomock.NewConn()
c.Command("SCAN", int64(0), "MATCH", "*", "COUNT", 100).Expect([]interface{}{
[]uint8("0"),
[]interface{}{[]uint8("test-key")},
})
newStorage := testMustNewStorageWithConn(t, c)
var count int
// Directly close and end walking.
closer := make(chan struct{}, 1)
closer <- struct{}{}
err := newStorage.WalkKeys("*", closer, func(key string) error {
count++
return nil
})
if err != nil {
t.Fatal("expected", nil, "got", err)
}
if count != 0 {
t.Fatal("expected", 0, "got", count)
}
}
开发者ID:xh3b4sd,项目名称:anna,代码行数:25,代码来源:string_storage_test.go
示例3: TestSetRedisHashKeysRedisError
func TestSetRedisHashKeysRedisError(t *testing.T) {
redigomock.Clear()
redigomock.Command("INCR", "moredis:mapindexcounter").ExpectError(errors.New("redis error"))
collectionConfig := CollectionConfig{Maps: []MapConfig{MapConfig{}}}
err := SetRedisHashKeys(redigomock.NewConn(), &collectionConfig)
assert.EqualError(t, err, "redis error")
}
开发者ID:bgveenstra,项目名称:moredis,代码行数:7,代码来源:moredis_test.go
示例4: Test_ScoredSetStorage_WalkScoredSet_CloseAfterCallback
func Test_ScoredSetStorage_WalkScoredSet_CloseAfterCallback(t *testing.T) {
c := redigomock.NewConn()
c.Command("ZSCAN", "prefix:test-key", int64(0), "COUNT", 100).Expect([]interface{}{
[]uint8("0"),
[]interface{}{[]uint8("test-value-1"), []uint8("0.8"), []uint8("test-value-2"), []uint8("0.8")},
})
newStorage := testMustNewStorageWithConn(t, c)
var count int
closer := make(chan struct{}, 1)
err := newStorage.WalkScoredSet("test-key", closer, func(element string, score float64) error {
count++
// Close and end walking.
closer <- struct{}{}
return nil
})
if err != nil {
t.Fatal("expected", nil, "got", err)
}
if count != 1 {
t.Fatal("expected", 1, "got", count)
}
}
开发者ID:xh3b4sd,项目名称:anna,代码行数:27,代码来源:scored_set_storage_test.go
示例5: Test_ScoredSetStorage_WalkScoredSet_CloseDirectly
func Test_ScoredSetStorage_WalkScoredSet_CloseDirectly(t *testing.T) {
c := redigomock.NewConn()
c.Command("ZSCAN", "prefix:test-key", int64(0), "COUNT", 100).Expect([]interface{}{
[]uint8("0"),
[]interface{}{[]uint8("test-value-1"), []uint8("0.8"), []uint8("test-value-2"), []uint8("0.8")},
})
newStorage := testMustNewStorageWithConn(t, c)
// Directly close and end walking.
closer := make(chan struct{}, 1)
closer <- struct{}{}
var values []interface{}
err := newStorage.WalkScoredSet("test-key", closer, func(element string, score float64) error {
values = append(values, element, score)
return nil
})
if err != nil {
t.Fatal("expected", nil, "got", err)
}
if values != nil {
t.Fatal("expected", nil, "got", values)
}
}
开发者ID:xh3b4sd,项目名称:anna,代码行数:25,代码来源:scored_set_storage_test.go
示例6: Test_CLG_Input_SetInformationSequenceError
func Test_CLG_Input_SetInformationSequenceError(t *testing.T) {
newCLG := MustNew()
newCtx := context.MustNew()
newServiceCollection := testMustNewServiceCollection(t)
// Prepare the storage connection to fake a returned error.
newInput := "test input"
informationIDKey := key.NewNetworkKey("information-sequence:%s:information-id", newInput)
// Our test ID factory always returns the same ID. That way we are able to
// check for the ID being used during the test.
newID, err := newServiceCollection.ID().New()
if err != nil {
t.Fatal("expected", nil, "got", err)
}
informationSequenceKey := key.NewNetworkKey("information-id:%s:information-sequence", newID)
c := redigomock.NewConn()
c.Command("GET", "prefix:"+informationIDKey).ExpectError(redigo.ErrNil)
c.Command("SET", "prefix:"+informationIDKey, string(newID)).Expect("OK")
c.Command("SET", "prefix:"+informationSequenceKey, newInput).ExpectError(invalidConfigError)
newStorageCollection := testMustNewStorageCollectionWithConn(t, c)
// Set prepared storage to CLG we want to test.
newCLG.(*clg).StorageCollection = newStorageCollection
newCLG.(*clg).ServiceCollection = newServiceCollection
// Execute CLG.
err = newCLG.(*clg).calculate(newCtx, newInput)
if !IsInvalidConfig(err) {
t.Fatal("expected", true, "got", false)
}
}
开发者ID:xh3b4sd,项目名称:anna,代码行数:32,代码来源:calculate_test.go
示例7: TestPuts
func TestPuts(t *testing.T) {
conn := redigomock.NewConn()
q := NewQueue(conn)
//Low
conn.GenericCommand("RPUSH").Expect(int64(1))
l, err := q.PutLow("test1", "val1")
if err != nil {
t.Error("Should not return error")
}
if l != 1 {
t.Error("Should return 1")
}
//Normal
conn.GenericCommand("RPUSH").Expect(int64(1))
l, err = q.PutNormal("test1", "val1")
if err != nil {
t.Error("Should not return error")
}
if l != 1 {
t.Error("Should return 1")
}
//High
conn.GenericCommand("RPUSH").Expect(int64(1))
l, err = q.PutHigh("test1", "val1")
if err != nil {
t.Error("Should not return error")
}
if l != 1 {
t.Error("Should return 1")
}
}
开发者ID:Gerifield,项目名称:go-little-red-queue,代码行数:35,代码来源:queue_test.go
示例8: Test_ScoredSetStorage_GetHighestScoredElements_Success
func Test_ScoredSetStorage_GetHighestScoredElements_Success(t *testing.T) {
c := redigomock.NewConn()
c.Command("ZREVRANGE", "prefix:foo", 0, 2, "WITHSCORES").Expect([]interface{}{
[]uint8("one"), []uint8("0.8"), []uint8("two"), []uint8("0.5"),
})
newStorage := testMustNewStorageWithConn(t, c)
values, err := newStorage.GetHighestScoredElements("foo", 2)
if err != nil {
t.Fatal("expected", nil, "got", err)
}
if len(values) != 4 {
t.Fatal("expected", 1, "got", len(values))
}
if values[0] != "one" {
t.Fatal("expected", "one", "got", values[0])
}
if values[1] != "0.8" {
t.Fatal("expected", "0.8", "got", values[1])
}
if values[2] != "two" {
t.Fatal("expected", "two", "got", values[2])
}
if values[3] != "0.5" {
t.Fatal("expected", "0.5", "got", values[3])
}
}
开发者ID:xh3b4sd,项目名称:anna,代码行数:28,代码来源:scored_set_storage_test.go
示例9: Test_SetStorage_WalkSet_CloseDirectly
func Test_SetStorage_WalkSet_CloseDirectly(t *testing.T) {
c := redigomock.NewConn()
c.Command("SSCAN", "prefix:test-key", int64(0), "COUNT", 100).Expect([]interface{}{
[]uint8("0"),
[]interface{}{[]uint8("test-value-1"), []uint8("test-value-2")},
})
newStorage := testMustNewStorageWithConn(t, c)
// Directly close and end walking.
closer := make(chan struct{}, 1)
closer <- struct{}{}
var element1 string
err := newStorage.WalkSet("test-key", closer, func(element string) error {
element1 = element
return nil
})
if err != nil {
t.Fatal("expected", nil, "got", err)
}
if element1 != "" {
t.Fatal("expected", "", "got", element1)
}
}
开发者ID:xh3b4sd,项目名称:anna,代码行数:25,代码来源:set_storage_test.go
示例10: defaultMockDialConfig
func defaultMockDialConfig() mockDialConfig {
newConfig := mockDialConfig{
RedisConn: redigomock.NewConn(),
}
return newConfig
}
开发者ID:xh3b4sd,项目名称:anna,代码行数:7,代码来源:dial.go
示例11: Test_StringStorage_WalkKeys_CloseAfterCallback
func Test_StringStorage_WalkKeys_CloseAfterCallback(t *testing.T) {
c := redigomock.NewConn()
c.Command("SCAN", int64(0), "MATCH", "*", "COUNT", 100).Expect([]interface{}{
[]uint8("0"),
[]interface{}{[]uint8("test-key")},
})
newStorage := testMustNewStorageWithConn(t, c)
var count int
var element1 string
closer := make(chan struct{}, 1)
err := newStorage.WalkKeys("*", closer, func(key string) error {
count++
element1 = key
// Close and end walking.
closer <- struct{}{}
return nil
})
if err != nil {
t.Fatal("expected", nil, "got", err)
}
if count != 1 {
t.Fatal("expected", 1, "got", count)
}
if element1 != "test-key" {
t.Fatal("expected", "test-key", "got", element1)
}
}
开发者ID:xh3b4sd,项目名称:anna,代码行数:32,代码来源:string_storage_test.go
示例12: TestNewQueue
func TestNewQueue(t *testing.T) {
conn := redigomock.NewConn()
q := NewQueue(conn)
if q.Prefix != "queue" {
t.Error("Wrong prefix")
}
}
开发者ID:Gerifield,项目名称:go-little-red-queue,代码行数:8,代码来源:queue_test.go
示例13: TestNewQueueWithPrefix
func TestNewQueueWithPrefix(t *testing.T) {
conn := redigomock.NewConn()
q := NewQueueWithPrefix(conn, "test")
if q.Prefix != "test" {
t.Error("Wrong prefix")
}
}
开发者ID:Gerifield,项目名称:go-little-red-queue,代码行数:9,代码来源:queue_test.go
示例14: TestProbabilityOfLabel
func TestProbabilityOfLabel(t *testing.T) {
conn := redigomock.NewConn()
conn.Command("MGET", spamCount, totalCount).Expect(pLabelResp)
dist := mockRedisProbDist(conn)
result, _ := dist.ProbabilityOfLabel(SPAM)
expected := .25
if expected != result {
t.Error("Expected", expected, "got", result)
}
}
开发者ID:vroomwaddle,项目名称:spamlab,代码行数:10,代码来源:probability_test.go
示例15: TestSetRedisHashKeys
func TestSetRedisHashKeys(t *testing.T) {
redigomock.Clear()
redigomock.Command("INCR", "moredis:mapindexcounter").Expect(int64(1))
collectionConfig := CollectionConfig{Maps: []MapConfig{MapConfig{}}}
err := SetRedisHashKeys(redigomock.NewConn(), &collectionConfig)
assert.Nil(t, err)
assert.Equal(t, collectionConfig.Maps[0].HashKey, "moredis:maps:1")
}
开发者ID:bgveenstra,项目名称:moredis,代码行数:10,代码来源:moredis_test.go
示例16: TestProbabilityOfTextGivenLabel
func TestProbabilityOfTextGivenLabel(t *testing.T) {
conn := redigomock.NewConn()
conn.Command("MGET", spamWordCount, spamHelloCount).Expect(spamWordCountResp)
dist := mockRedisProbDist(conn)
result, _ := dist.ProbabilityOfTextGivenLabel(text, SPAM)
expected := .25
if expected != result {
t.Error("Expected", expected, "got", result)
}
}
开发者ID:vroomwaddle,项目名称:spamlab,代码行数:10,代码来源:probability_test.go
示例17: PrepareRedisTest
func PrepareRedisTest() (*redigomock.Conn, *database.Redis) {
mock := redigomock.NewConn()
pool := &RedisPoolMock{
Conn: mock,
}
conn := database.NewRedisCustomPool(pool)
return mock, conn
}
开发者ID:wsnipex,项目名称:mirrorbits,代码行数:11,代码来源:redis.go
示例18: Test_ScoredSetStorage_SetElementByScore_Success
func Test_ScoredSetStorage_SetElementByScore_Success(t *testing.T) {
c := redigomock.NewConn()
c.Command("ZADD", "prefix:key", 0.8, "element").Expect(int64(1))
newStorage := testMustNewStorageWithConn(t, c)
err := newStorage.SetElementByScore("key", "element", 0.8)
if err != nil {
t.Fatal("expected", nil, "got", err)
}
}
开发者ID:xh3b4sd,项目名称:anna,代码行数:11,代码来源:scored_set_storage_test.go
示例19: Test_ScoredSetStorage_SetElementByScore_Error
func Test_ScoredSetStorage_SetElementByScore_Error(t *testing.T) {
c := redigomock.NewConn()
c.Command("ZADD", "prefix:key", 0.8, "element").ExpectError(queryExecutionFailedError)
newStorage := testMustNewStorageWithConn(t, c)
err := newStorage.SetElementByScore("key", "element", 0.8)
if !IsQueryExecutionFailed(err) {
t.Fatal("expected", true, "got", false)
}
}
开发者ID:xh3b4sd,项目名称:anna,代码行数:11,代码来源:scored_set_storage_test.go
示例20: Test_SetStorage_Error
func Test_SetStorage_Error(t *testing.T) {
c := redigomock.NewConn()
c.Command("SET", "prefix:foo", "bar").ExpectError(queryExecutionFailedError)
newStorage := testMustNewStorageWithConn(t, c)
err := newStorage.Set("foo", "bar")
if !IsQueryExecutionFailed(err) {
t.Fatal("expected", true, "got", false)
}
}
开发者ID:xh3b4sd,项目名称:anna,代码行数:11,代码来源:set_storage_test.go
注:本文中的github.com/rafaeljusto/redigomock.NewConn函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论