File: test_base.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 (53 lines) | stat: -rw-r--r-- 1,434 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
# frozen_string_literal: true
# rubocop:todo all

module Mongo
  module CRUD

    class CRUDTestBase

      # The test description.
      #
      # @return [ String ] description The test description.
      attr_reader :description

      # The expected command monitoring events.
      attr_reader :expectations

      def setup_fail_point(client)
        if @fail_point_command
          client.use(:admin).command(@fail_point_command)
        end
      end

      def clear_fail_point(client)
        if @fail_point_command
          ClientRegistry.instance.global_client('root_authorized').use(:admin).command(BSON::Document.new(@fail_point_command).merge(mode: "off"))
        end
      end

      private

      def resolve_target(client, operation)
        if operation.database_options
          # Some CRUD spec tests specify "database options". In Ruby there is
          # no facility to specify options on a database, hence these are
          # lifted to the client.
          client = client.with(operation.database_options)
        end
        case operation.object
        when 'collection'
          client[@spec.collection_name].with(operation.collection_options)
        when 'database'
          client.database
        when 'client'
          client
        when 'gridfsbucket'
          client.database.fs
        else
          raise "Unknown target #{operation.object}"
        end
      end
    end
  end
end