File: status_spec.rb

package info (click to toggle)
ruby-mongo 2.21.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 14,764 kB
  • sloc: ruby: 108,806; makefile: 5; sh: 2
file content (97 lines) | stat: -rw-r--r-- 2,650 bytes parent folder | download
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
96
97
# frozen_string_literal: true
# rubocop:todo all

require 'lite_spec_helper'

describe 'Mongo::Crypt::Binding' do
  describe 'mongocrypt_status_t binding' do
    require_libmongocrypt

    let(:status) { Mongo::Crypt::Binding.mongocrypt_status_new }
    let(:message) { "Operation unauthorized" }

    let(:status_with_info) do
      Mongo::Crypt::Binding.mongocrypt_status_set(
        status,
        :error_client,
        401,
        message,
        message.length + 1
      )

      status
    end

    after do
      Mongo::Crypt::Binding.mongocrypt_status_destroy(status)
    end

    describe '#mongocrypt_status_new' do
      it 'returns a pointer' do
        expect(status).to be_a_kind_of(FFI::Pointer)
      end
    end

    describe '#mongocrypt_status_type' do
      context 'when status has no type' do
        it 'returns :ok/0' do
          expect(Mongo::Crypt::Binding.mongocrypt_status_type(status)).to eq(:ok)
        end
      end

      context 'when status has type' do
        it 'returns type' do
          expect(Mongo::Crypt::Binding.mongocrypt_status_type(status_with_info)).to eq(:error_client)
        end
      end
    end

    describe '#mongocrypt_status_code' do
      context 'when status has no code' do
        it 'returns 0' do
          expect(Mongo::Crypt::Binding.mongocrypt_status_code(status)).to eq(0)
        end
      end

      context 'when status has code' do
        it 'returns code' do
          expect(Mongo::Crypt::Binding.mongocrypt_status_code(status_with_info)).to eq(401)
        end
      end
    end

    describe '#mongocrypt_status_message' do
      context 'when status has no message' do
        it 'returns nil' do
          expect(Mongo::Crypt::Binding.mongocrypt_status_message(status, nil)).to eq(nil)
        end
      end

      context 'when status has message' do
        it 'returns message' do
          expect(Mongo::Crypt::Binding.mongocrypt_status_message(status_with_info, nil)).to eq(message)
        end
      end
    end

    describe '#mongocrypt_status_ok' do
      context 'when status_type is not ok' do
        it 'returns false' do
          expect(Mongo::Crypt::Binding.mongocrypt_status_ok(status_with_info)).to be false
        end
      end

      context 'when status_type is ok' do
        let(:message) { 'Operation successful' }
        let(:status_with_info) do
          Mongo::Crypt::Binding.mongocrypt_status_set(status, :ok, 200, message, message.length + 1)
          status
        end

        it 'returns true' do
          expect(Mongo::Crypt::Binding.mongocrypt_status_ok(status_with_info)).to be true
        end
      end
    end
  end
end