File: connection_spec.rb

package info (click to toggle)
ruby-fakeredis 0.8.0-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 628 kB
  • sloc: ruby: 4,868; makefile: 2
file content (85 lines) | stat: -rw-r--r-- 2,434 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
require 'spec_helper'

module FakeRedis
  describe "ConnectionMethods" do

    before(:each) do
      @client = Redis.new
    end

  if fakeredis?
    it "should authenticate to the server" do
      expect(@client.auth("pass")).to eq("OK")
    end

    it "should re-use the same instance with the same host & port" do
      @client1 = Redis.new(:host => "localhost", :port => 1234)
      @client2 = Redis.new(:host => "localhost", :port => 1234)
      @client3 = Redis.new(:host => "localhost", :port => 5678)

      @client1.set("key1", "1")
      expect(@client2.get("key1")).to eq("1")
      expect(@client3.get("key1")).to be_nil

      @client2.set("key2", "2")
      expect(@client1.get("key2")).to eq("2")
      expect(@client3.get("key2")).to be_nil

      @client3.set("key3", "3")
      expect(@client1.get("key3")).to be_nil
      expect(@client2.get("key3")).to be_nil

      expect(@client1.dbsize).to eq(2)
      expect(@client2.dbsize).to eq(2)
      expect(@client3.dbsize).to eq(1)
    end

    it "should connect to a specific database" do
      @client1 = Redis.new(:host => "localhost", :port => 1234, :db => 0)
      @client1.set("key1", "1")
      @client1.select(0)
      expect(@client1.get("key1")).to eq("1")

      @client2 = Redis.new(:host => "localhost", :port => 1234, :db => 1)
      @client2.set("key1", "1")
      @client2.select(1)
      expect(@client2.get("key1")).to eq("1")
    end

    it "should not error with shutdown" do
      expect { @client.shutdown }.not_to raise_error
    end

    it "should not error with quit" do
      expect { @client.quit }.not_to raise_error
    end
  end

    it "should handle multiple clients using the same db instance" do
      @client1 = Redis.new(:host => "localhost", :port => 6379, :db => 1)
      @client2 = Redis.new(:host => "localhost", :port => 6379, :db => 2)

      @client1.set("key1", "one")
      expect(@client1.get("key1")).to eq("one")

      @client2.set("key2", "two")
      expect(@client2.get("key2")).to eq("two")

      expect(@client1.get("key1")).to eq("one")
    end

    it "should not error with a disconnected client" do
      @client1 = Redis.new
      @client1.close
      expect(@client1.get("key1")).to be_nil
    end

    it "should echo the given string" do
      expect(@client.echo("something")).to eq("something")
    end

    it "should ping the server" do
      expect(@client.ping).to eq("PONG")
    end
  end
end