Sha256: cbfcc7a28099490396b5e6ea360abfca182ea72c36f4dd620368a31d6fe519b4

Contents?: true

Size: 1.54 KB

Versions: 23

Compression:

Stored size: 1.54 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

23 entries across 20 versions & 3 rubygems

Version Path
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/winrm-elevated-1.1.0/spec/spec_helper.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.5.0/gems/winrm-elevated-1.1.0/spec/spec_helper.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.5.0/gems/winrm-elevated-1.1.0/spec/spec_helper.rb
vagrant-unbundled-2.2.3.0 vendor/bundle/ruby/2.5.0/gems/winrm-elevated-1.1.0/spec/spec_helper.rb
vagrant-unbundled-2.2.2.0 vendor/bundle/ruby/2.5.0/gems/winrm-elevated-1.1.0/spec/spec_helper.rb
vagrant-unbundled-2.2.0.0 vendor/bundle/ruby/2.5.0/gems/winrm-elevated-1.1.0/spec/spec_helper.rb
vagrant-unbundled-2.1.4.0 vendor/bundle/ruby/2.5.0/gems/winrm-elevated-1.1.0/spec/spec_helper.rb
vagrant-unbundled-2.1.2.0 vendor/bundle/ruby/2.3.0/gems/winrm-elevated-1.1.0/spec/spec_helper.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/winrm-elevated-1.1.0/spec/spec_helper.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/winrm-elevated-1.1.0/spec/spec_helper.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/winrm-elevated-1.1.0/spec/spec_helper.rb
vagrant-unbundled-2.1.1.0 vendor/bundle/ruby/2.5.0/gems/winrm-elevated-1.1.0/spec/spec_helper.rb
vagrant-unbundled-2.0.4.0 vendor/bundle/ruby/2.5.0/gems/winrm-elevated-1.1.0/spec/spec_helper.rb
vagrant-unbundled-2.0.3.0 vendor/bundle/ruby/2.5.0/gems/winrm-elevated-1.1.0/spec/spec_helper.rb
vagrant-unbundled-2.0.2.0 vendor/bundle/ruby/2.5.0/gems/winrm-elevated-1.1.0/spec/spec_helper.rb
vagrant-unbundled-2.0.2.0 vendor/bundle/ruby/2.4.0/gems/winrm-elevated-1.1.0/spec/spec_helper.rb
vagrant-unbundled-2.0.1.0 vendor/bundle/ruby/2.4.0/gems/winrm-elevated-1.1.0/spec/spec_helper.rb
vagrant-unbundled-2.0.0.1 vendor/bundle/ruby/2.4.0/gems/winrm-elevated-1.1.0/spec/spec_helper.rb
vagrant-unbundled-1.9.8.1 vendor/bundle/ruby/2.4.0/gems/winrm-elevated-1.1.0/spec/spec_helper.rb
vagrant-unbundled-1.9.7.1 vendor/bundle/ruby/2.4.0/gems/winrm-elevated-1.1.0/spec/spec_helper.rb