Skip to content

Capture commands set to go-redis for testing purposes

License

Notifications You must be signed in to change notification settings

mjc-gh/redis-test-hook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Redis Test Hooks

go-redis-test-hook Go Reference

Capture commands set to Redis for testing purposes with a hook.

func TestDoesSomethingWithRedis(t *testing.T) {
    // Setup
    hook := redistesthooks.New()

    rdb := redis.NewClient(&redis.Options{Addr: "localhost:6379"})
    rdb.AddHook(hook)

    // Do stuff with redis
    rdb.Set(ctx, "key", 42, time.Duration(0))
    rdb.Get(ctx, "key")

    // Write assertions against captures
    assert.Equal(t, "SET key 42", hook.Captures[0].String())
    assert.Equal(t, "GET key", hook.Captures[1].String())

    // Clear captures
    hook.Reset()
}

About

Capture commands set to go-redis for testing purposes

Topics

Resources

License

Stars

Watchers

Forks