File: ipv4_spec.rb

package info (click to toggle)
ruby-mongo 2.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,332 kB
  • sloc: ruby: 45,579; makefile: 5
file content (95 lines) | stat: -rw-r--r-- 1,871 bytes parent folder | download | duplicates (4)
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
86
87
88
89
90
91
92
93
94
95
require 'spec_helper'

describe Mongo::Address::IPv4 do

  let(:resolver) do
    described_class.new(*described_class.parse(address))
  end

  describe 'self.parse' do

    context 'when a port is provided' do

      it 'returns the host and port' do
        expect(described_class.parse('127.0.0.1:27017')).to eq(['127.0.0.1', 27017])
      end
    end

    context 'when no port is provided' do

      it 'returns the host and port' do
        expect(described_class.parse('127.0.0.1')).to eq(['127.0.0.1', 27017])
      end
    end
  end

  describe '#initialize' do

    context 'when a port is provided' do

      let(:address) do
        '127.0.0.1:27017'
      end

      it 'sets the port' do
        expect(resolver.port).to eq(27017)
      end

      it 'sets the host' do
        expect(resolver.host).to eq('127.0.0.1')
      end
    end

    context 'when no port is provided' do

      let(:address) do
        '127.0.0.1'
      end

      it 'sets the port to 27017' do
        expect(resolver.port).to eq(27017)
      end

      it 'sets the host' do
        expect(resolver.host).to eq('127.0.0.1')
      end
    end
  end

  describe '#socket' do

    let(:address) do
      '127.0.0.1'
    end

    context 'when ssl options are provided' do

      let(:socket) do
        resolver.socket(5, :ssl => true)
      end

      it 'returns an ssl socket' do
        expect(socket).to be_a(Mongo::Socket::SSL)
      end

      it 'sets the family as ipv4' do
        expect(socket.family).to eq(Socket::PF_INET)
      end
    end

    context 'when ssl options are not provided' do

      let(:socket) do
        resolver.socket(5)
      end

      it 'returns a tcp socket' do
        expect(socket).to be_a(Mongo::Socket::TCP)
      end

      it 'sets the family a ipv4' do
        expect(socket.family).to eq(Socket::PF_INET)
      end
    end
  end
end