Sha256: 2378c1c3fffdd615a2fc2cf9c8c8cfea34874551d526fbaa6de025ab382d46bd

Contents?: true

Size: 1.04 KB

Versions: 5

Compression:

Stored size: 1.04 KB

Contents

module TestClient
  def test_client
    if defined? $test_client and $test_client.ping
      return $test_client
    end

    candidate_client = Riak::Client.new test_client_configuration

    live = candidate_client.ping
    
    return $test_client = candidate_client if live
  end

  def test_client_configuration
    TestClient.test_client_configuration
  end

  def self.test_client_configuration
    if defined? $test_client_configuration
      return $test_client_configuration
    end

    config_path = File.expand_path '../test_client.yml', __FILE__
    config = YAML.load_file(config_path).symbolize_keys

    if config[:nodes]
      new_nodes = config[:nodes].map(&:symbolize_keys)
      config[:nodes] = new_nodes
    end

    $test_client_configuration = config
  end

  def random_bucket(name='test_client')
    bucket_name = [name, Time.now.to_i, random_key].join('-')
    test_client.bucket bucket_name
  end

  def random_key
    rand(36**10).to_s(36)
  end
end

RSpec.configure do |config|
  config.include TestClient, test_client: true
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
riak-client-2.2.0.pre1 spec/support/test_client.rb
riak-client-2.1.0 spec/support/test_client.rb
riak-client-2.0.0 spec/support/test_client.rb
riak-client-2.0.0.rc2 spec/support/test_client.rb
riak-client-2.0.0.rc1 spec/support/test_client.rb