Sha256: 2711e8ff0a0bce6e3e5c4ba8794c034721dd03b0be642de9b580e2fd5fc5ed26

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

# encoding: UTF-8
require 'winrm'
require 'winrm-elevated'
require_relative 'matchers'

# Creates a WinRM connection for integration tests
module ConnectionHelper
  def winrm_connection
    WinRM::Connection.new(winrm_config)
  end

  def elevated_shell
    @elevated_shell ||= winrm_connection.shell(:elevated)
  end

  def winrm_config
    unless @winrm_config
      path = File.expand_path("#{File.dirname(__FILE__)}/config.yml")
      unless File.exist?(path)
        path = File.expand_path("#{File.dirname(__FILE__)}/config-example.yml")
      end
      @winrm_config = symbolize_keys(YAML.load(File.read(path)))
      @winrm_config[:endpoint] = ENV['winrm_endpoint'] if ENV['winrm_endpoint']
      @winrm_config[:user] = ENV['winrm_user'] if ENV['winrm_user']
      @winrm_config[:password] = ENV['winrm_password'] if ENV['winrm_password']
    end
    @winrm_config
  end

  def username
    winrm_config[:user]
  end

  def password
    winrm_config[:password]
  end

  # rubocop:disable Metrics/MethodLength
  def symbolize_keys(hash)
    hash.each_with_object({}) do |(key, value), result|
      new_key = case key
                when String then key.to_sym
                else key
                end
      new_value = case value
                  when Hash then symbolize_keys(value)
                  else value
                  end
      result[new_key] = new_value
      result
    end
  end
  # rubocop:enable Metrics/MethodLength
end

RSpec.configure do |config|
  config.include(ConnectionHelper)
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
winrm-elevated-1.0.1 spec/spec_helper.rb