Golang Testing — Mocking Redis

Golang Testing — Mocking Redis

Golang Testing — Mocking Redis. I recently discovered how to mock Redis in my testing environments with little friction. When testing our applications we often have a lot of external dependencies, such as Redis. When testing we should try to mock this.

When testing our applications we often have a lot of external dependencies, and often we’re not running our tests in an environment where we have room to boot up Redis, MySQL etc.

Recently I was trying to solve the problem of needing a Redis connection in one of my applications, but I didn’t want to have to keep a Redis server running whilst I ran my tests, I felt this was unnecessary.

I stumbled upon an elegant solution to this: https://github.com/alicebob/miniredis

This library spins up a Redis compatible server in your application that you can use without dependencies when running your tests in any environment. This is perfect!

Say in your application you’re making use of a redisClient which is available globally in your package scope:

In this case we’re using `github.com/go-redis/redis_` as our Redis library of choice._

redis programming golang tdd testing

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Where To Learn Test Programming — July 2020 Edition

What do you do when you have lots of free time on your hands? Why not learn test programming strategies and approaches?

Redis Transactions & Long-Running Lua Scripts

Redis Lua scripting is the popularly recommended approach for handling transactions. Learn the common Lua Scripts error and how to handle for sentinel systems. Redis offers two mechanisms for handling transactions – MULTI/EXEC based transactions and Lua scripts evaluation. Redis Lua scripting is the recommended approach and is fairly popular in usage.

How to Do API Testing?

API endpoint when you send the get request to that URL it returns the JSON response. In this article, I am going to use postman assertions for all the examples since it is the most popular tool. But this article is not intended only for the postman tool.

Test Driven Development (TDD) with React Testing Library & Mock Service Worker

Let’s step up our testing game with two useful libraries that lend themselves excellently to a TDD approach.

Testing Microservices Applications

The shift towards microservices and modular applications makes testing more important and more challenging at the same time. Learn more here.