Sha256: b94449f365eed439f1169bafc0641e4cf69c4222b13eb563c3023671f2086660

Contents?: true

Size: 1.49 KB

Versions: 22

Compression:

Stored size: 1.49 KB

Contents

module Ey
  module Core
    module TestHelpers
      module ClientHelpers
        def create_client(attributes={})
          token = if (user = attributes.delete(:user)) && Ey::Core::Client.mocking?
                    core = Ey::Core::Client::Mock.data.values.find { |c| c[:users][user.identity] }
                    core[:users][user.identity]["token"]
                  end
          token ||= begin
                      token_dotfile = YAML.load_file(File.expand_path("/../../../.token"), __FILE__) rescue {}
                      ENV["CORE_TOKEN"] || token_dotfile[ENV["CORE_URL"]] || "a4bf6558da8c1051536d1596b8931ebd346aff0b"
                    end

          merged_attributes = attributes.merge(token: token, cache: true)
          merged_attributes.merge!(logger: Logger.new(STDOUT)) if ENV['VERBOSE']

          Ey::Core::Client.new(merged_attributes)
        end

        def create_server_client(server, attributes={})
          unless core = Ey::Core::Client::Mock.data.values.find { |data| data[:servers][server.identity] }
            raise "Failed to find server in mock data: #{server}"
          end

          token = core[:servers][server.identity]["token"]

          merged_attributes = attributes.merge(token: token, cache: true)
          merged_attributes.merge!(logger: Logger.new(STDOUT)) if ENV['VERBOSE']

          Ey::Core::Client.new(merged_attributes)
        end

        def create_unauthenticated_client
          Ey::Core::Client.new(token: nil)
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
ey-core-3.6.0.autoscaling1 lib/ey-core/test_helpers/client_helpers.rb
ey-core-3.6.4 lib/ey-core/test_helpers/client_helpers.rb
ey-core-3.6.3 lib/ey-core/test_helpers/client_helpers.rb
ey-core-3.6.1 lib/ey-core/test_helpers/client_helpers.rb
groove-ey-core-3.6.3 lib/ey-core/test_helpers/client_helpers.rb
groove-ey-core-3.6.2 lib/ey-core/test_helpers/client_helpers.rb
groove-ey-core-3.6.1 lib/ey-core/test_helpers/client_helpers.rb
ey-core-3.5.0 lib/ey-core/test_helpers/client_helpers.rb
ey-core-3.4.4 lib/ey-core/test_helpers/client_helpers.rb
ey-core-3.4.2 lib/ey-core/test_helpers/client_helpers.rb
ey-core-3.4.1 lib/ey-core/test_helpers/client_helpers.rb
ey-core-3.4.0 lib/ey-core/test_helpers/client_helpers.rb
ey-core-3.3.1 lib/ey-core/test_helpers/client_helpers.rb
ey-core-3.3.0 lib/ey-core/test_helpers/client_helpers.rb
ey-core-3.2.6 lib/ey-core/test_helpers/client_helpers.rb
ey-core-3.2.5 lib/ey-core/test_helpers/client_helpers.rb
ey-core-3.2.4 lib/ey-core/test_helpers/client_helpers.rb
ey-core-3.2.3 lib/ey-core/test_helpers/client_helpers.rb
ey-core-3.2.2 lib/ey-core/test_helpers/client_helpers.rb
ey-core-3.2.1 lib/ey-core/test_helpers/client_helpers.rb