All Projects → go-redis → redismock

go-redis / redismock

Licence: BSD-2-Clause license
Redis client Mock

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to redismock

Shallow Render
Angular testing made easy with shallow rendering and easy mocking. https://getsaf.github.io/shallow-render
Stars: ✭ 242 (+47.56%)
Mutual labels:  mock
openman
Postman to OpenAPI Spec converter with mocking and documentation
Stars: ✭ 17 (-89.63%)
Mutual labels:  mock
walletconnect-test-wallet
Test Wallet (Web)
Stars: ✭ 163 (-0.61%)
Mutual labels:  mock
Jest Localstorage Mock
A module to mock window.localStorage and window.sessionStorage in Jest
Stars: ✭ 247 (+50.61%)
Mutual labels:  mock
Vue Element Admin
🎉 A magical vue admin https://panjiachen.github.io/vue-element-admin
Stars: ✭ 73,044 (+44439.02%)
Mutual labels:  mock
xrm-mock-generator
📖  Generates a mock Xrm.Page object. Commonly used by xrm-mock to test Dynamics 365 client-side customisations.
Stars: ✭ 15 (-90.85%)
Mutual labels:  mock
Faker
Provides fake data to your Android apps :)
Stars: ✭ 234 (+42.68%)
Mutual labels:  mock
puppet-mock
Puppet Mocker for Wechaty (& A Puppet Template Starter)
Stars: ✭ 33 (-79.88%)
Mutual labels:  mock
go-github-mock
A library to aid unittesting code that uses Golang's Github SDK
Stars: ✭ 63 (-61.59%)
Mutual labels:  mock
aem-stubs
Tool for providing sample data for AEM applications in a simple and flexible way. Stubbing server on AEM, no separate needed.
Stars: ✭ 40 (-75.61%)
Mutual labels:  mock
Gripmock
gRPC Mock Server
Stars: ✭ 248 (+51.22%)
Mutual labels:  mock
Http Fake Backend
Build a fake backend by providing the content of JSON files or JavaScript objects through configurable routes.
Stars: ✭ 253 (+54.27%)
Mutual labels:  mock
HttpClientMock
Library for mocking Apache HttpClient.
Stars: ✭ 41 (-75%)
Mutual labels:  mock
Vuex Mock Store
✅Simple and straightforward Vuex Store mock for vue-test-utils
Stars: ✭ 246 (+50%)
Mutual labels:  mock
graphql-mock-api
A GraphQL mock to any GraphQL schema
Stars: ✭ 28 (-82.93%)
Mutual labels:  mock
Mockoon
Mockoon is the easiest and quickest way to run mock APIs locally. No remote deployment, no account required, open source.
Stars: ✭ 3,448 (+2002.44%)
Mutual labels:  mock
DataAbstractions.Dapper
A light abstraction around Dapper and Dapper.Contrib that also maintains the behavior IDbConnection.
Stars: ✭ 37 (-77.44%)
Mutual labels:  mock
tplink-smarthome-simulator
TP-Link Smarthome Device Simulator
Stars: ✭ 55 (-66.46%)
Mutual labels:  mock
fe-dev-server
FE Dev Server target to help frontend web developers create view template, styles and js easily.
Stars: ✭ 30 (-81.71%)
Mutual labels:  mock
mocka
Mocka - The complete testing framework for LUA and Nginx
Stars: ✭ 26 (-84.15%)
Mutual labels:  mock

Redis client Mock

Provide mock test for redis query, Compatible with github.com/redis/go-redis/v9

Install

Confirm that you are using redis.Client the version is github.com/redis/go-redis/v9

go get github.com/go-redis/redismock/v9

Quick Start

RedisClient

var ctx = context.TODO()

func NewsInfoForCache(redisDB *redis.Client, newsID int) (info string, err error) {
	cacheKey := fmt.Sprintf("news_redis_cache_%d", newsID)
	info, err = redisDB.Get(ctx, cacheKey).Result()
	if err == redis.Nil {
		// info, err = call api()
		info = "test"
		err = redisDB.Set(ctx, cacheKey, info, 30 * time.Minute).Err()
	}
	return
}

func TestNewsInfoForCache(t *testing.T) {
	db, mock := redismock.NewClientMock()

	newsID := 123456789
	key := fmt.Sprintf("news_redis_cache_%d", newsID)

	// mock ignoring `call api()`

	mock.ExpectGet(key).RedisNil()
	mock.Regexp().ExpectSet(key, `[a-z]+`, 30 * time.Minute).SetErr(errors.New("FAIL"))

	_, err := NewsInfoForCache(db, newsID)
	if err == nil || err.Error() != "FAIL" {
		t.Error("wrong error")
	}

	if err := mock.ExpectationsWereMet(); err != nil {
		t.Error(err)
	}
}

RedisCluster

clusterClient, clusterMock := redismock.NewClusterMock()

Unsupported Command

RedisClient:

  • Subscribe / PSubscribe

RedisCluster

  • Subscribe / PSubscribe
  • Pipeline / TxPipeline
  • Watch
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].