From 7224f09c2a81f77ee0c133029b7a7c331d775788 Mon Sep 17 00:00:00 2001 From: Evgeni Gomziakov <60209991+egmzy@users.noreply.github.com> Date: Tue, 28 Mar 2023 18:02:13 +0300 Subject: [PATCH] feat: implement nodes method in cluster mock (#1260) --- src/index.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index ee05a7fc5..476f69104 100644 --- a/src/index.js +++ b/src/index.js @@ -251,8 +251,20 @@ RedisMock.Cluster = class RedisClusterMock extends RedisMock { } else { super() } - this.nodes = [] - nodesOptions.forEach(options => this.nodes.push(new RedisMock(options))) + nodesOptions.forEach(options => this.clusterNodes.all.push(new RedisMock(options))) + } + + clusterNodes = { + all: [], + master: [], + slave: [], + }; + + nodes(role = "all") { + if (role !== 'all' && role !== 'master' && role !== 'slave') { + throw new Error(`Invalid role "${role}". Expected "all", "master" or "slave"`); + } + return this.clusterNodes['all'] // temporary return all until implemented slave and master logic } }