Sha256: 4c919923b5e945816e5a3f0c7243924d7bce4d46d727cc976511745209d78c5e

Contents?: true

Size: 1.62 KB

Versions: 12

Compression:

Stored size: 1.62 KB

Contents

require 'mongo'
require 'support/lite_constraints'

RSpec.configure do |config|
  config.extend(LiteConstraints)
end

describe 'Mongo::Crypt::Binding' do
  describe 'binary_t bindings' do
    require_libmongocrypt

    let(:bytes) { [104, 101, 108, 108, 111] }

    let(:bytes_pointer) do
      # FFI::MemoryPointer automatically frees memory when it goes out of scope
      p = FFI::MemoryPointer.new(bytes.size)
      p.write_array_of_type(FFI::TYPE_UINT8, :put_uint8, bytes)
    end

    after do
      Mongo::Crypt::Binding.mongocrypt_binary_destroy(binary)
    end

    describe '#mongocrypt_binary_new' do
      let(:binary) { Mongo::Crypt::Binding.mongocrypt_binary_new }

      it 'returns a pointer' do
        expect(binary).to be_a_kind_of(FFI::Pointer)
      end
    end

    describe '#mongocrypt_binary_new_from_data' do
      let(:binary) { Mongo::Crypt::Binding.mongocrypt_binary_new_from_data(bytes_pointer, bytes.length) }

      it 'returns a pointer' do
        expect(binary).to be_a_kind_of(FFI::Pointer)
      end
    end

    describe '#mongocrypt_binary_data' do
      let(:binary) { Mongo::Crypt::Binding.mongocrypt_binary_new_from_data(bytes_pointer, bytes.length) }

      it 'returns the pointer to the data' do
        expect(Mongo::Crypt::Binding.mongocrypt_binary_data(binary)).to eq(bytes_pointer)
      end
    end

    describe '#mongocrypt_binary_len' do
      let(:binary) { Mongo::Crypt::Binding.mongocrypt_binary_new_from_data(bytes_pointer, bytes.length) }

      it 'returns the length of the data' do
        expect(Mongo::Crypt::Binding.mongocrypt_binary_len(binary)).to eq(bytes.length)
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
mongo-2.13.3 spec/mongo/crypt/binding/binary_spec.rb
mongo-2.13.2 spec/mongo/crypt/binding/binary_spec.rb
mongo-2.14.0.rc1 spec/mongo/crypt/binding/binary_spec.rb
mongo-2.13.1 spec/mongo/crypt/binding/binary_spec.rb
mongo-2.12.4 spec/mongo/crypt/binding/binary_spec.rb
mongo-2.13.0 spec/mongo/crypt/binding/binary_spec.rb
mongo-2.12.3 spec/mongo/crypt/binding/binary_spec.rb
mongo-2.13.0.rc1 spec/mongo/crypt/binding/binary_spec.rb
mongo-2.12.2 spec/mongo/crypt/binding/binary_spec.rb
mongo-2.13.0.beta1 spec/mongo/crypt/binding/binary_spec.rb
mongo-2.12.1 spec/mongo/crypt/binding/binary_spec.rb
mongo-2.12.0.rc0 spec/mongo/crypt/binding/binary_spec.rb