File: zstd_compression_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 (29 lines) | stat: -rw-r--r-- 887 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
# frozen_string_literal: true
# rubocop:todo all

require 'spec_helper'

describe 'Zstd compression' do
  min_server_version '4.2'
  require_zstd_compression

  before do
    authorized_client['test'].drop
  end

  context 'when client has snappy compressor option enabled' do
    it 'compresses the message to the server' do
      # Double check that the client has zstd compression enabled
      expect(authorized_client.options[:compressors]).to include('zstd')

      expect(Mongo::Protocol::Compressed).to receive(:new).twice.and_call_original
      expect(Zstd).to receive(:compress).twice.and_call_original
      expect(Zstd).to receive(:decompress).twice.and_call_original

      authorized_client['test'].insert_one(_id: 1, text: 'hello world')
      document = authorized_client['test'].find(_id: 1).first

      expect(document['text']).to eq('hello world')
    end
  end
end