diff --git a/Rakefile b/Rakefile index 9fcf217e..0541e9fd 100644 --- a/Rakefile +++ b/Rakefile @@ -33,6 +33,11 @@ namespace :test do sh('sh', '-c', "cd #{path} && config=test-runner.yaml ruby -I ../../lib docker_test.rb tests/*") end + task :winrm do + path = File.join(File.dirname(__FILE__), 'test', 'winrm') + sh('sh', '-c', "cd #{path} && ruby windows.rb") + end + task :vm do concurrency = ENV['CONCURRENCY'] || 4 path = File.join(File.dirname(__FILE__), 'test', 'integration') diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 00000000..131794e0 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,48 @@ +version: "master-{build}" + +os: Windows Server 2012 R2 +platform: + - x64 + +environment: + winrm_user: test_user + winrm_pass: Pass@word1 + + matrix: + - ruby_version: "21" + train_target: winrm://test_user@localhost:5985 + + - ruby_version: "21" + train_ssl: true + train_target: winrm://test_user@localhost:5986 + +clone_folder: c:\projects\train +clone_depth: 1 + +cache: + - C:\Ruby21\bin\gem + +install: + - systeminfo + - ps: net user /add $env:winrm_user $env:winrm_pass + - ps: net localgroup administrators $env:winrm_user /add + - ps: $env:winrm_cert = (New-SelfSignedCertificate -DnsName localhost -CertStoreLocation cert:\localmachine\my).Thumbprint + - ps: winrm create winrm/config/Listener?Address=*+Transport=HTTPS "@{Hostname=`"localhost`";CertificateThumbprint=`"$($env:winrm_cert)`"}" + - ps: winrm set winrm/config/client/auth '@{Basic="true"}' + - ps: winrm set winrm/config/service/auth '@{Basic="true"}' + - ps: winrm set winrm/config/service '@{AllowUnencrypted="true"}' + - ps: $env:PATH="C:\Ruby$env:ruby_version\bin;$env:PATH" + - ps: Write-Host $env:PATH + - gem install bundler --quiet --no-ri --no-rdoc + - gem update --system 2.4.5 + - ruby --version + - gem --version + - bundler --version + - ruby -r rubygems -e "p Gem.path" + +build_script: + - bundle install --without integration tools + +test_script: + - SET SPEC_OPTS=--format progress + - bundle exec rake test:winrm diff --git a/test/winrm/windows.rb b/test/winrm/windows.rb new file mode 100644 index 00000000..6e3555e7 --- /dev/null +++ b/test/winrm/windows.rb @@ -0,0 +1,62 @@ +#!/usr/bin/env ruby +# encoding: utf-8 +# +# Author:: Christoph Hartmann () + +require 'train' +require 'json' + +# expects the following env variables +# export winrm_user=test_user +# export winrm_pass=Pass@word1 +# export train_target='winrm://test_user@localhost:5985' +# export train_ssl='true' + +def get_os(backend, opts = {}) + # resolve configuration + target_config = Train.target_config(opts) + puts "Use the following config: #{target_config}" + + # initialize train + train = Train.create(backend, target_config) + + # start or reuse a connection + conn = train.connection + os = conn.os + + # get OS info + conf = { + name: os[:name], + family: os[:family], + release: os[:release], + arch: os[:arch], + } + + # close the connection + conn.close + conf +end + +def compare_hash(value, cmp) + value == cmp +end + +# check local +local = get_os('local') +puts "Detected the following OS (local): #{local}" + +# winrm over http +winrm = get_os('winrm', { + target: ENV['train_target'], + password: ENV['winrm_pass'], + ssl: ENV['train_ssl'], + self_signed: true, +}) +puts "Detected the following OS (remote): #{winrm}" + +# compare values +cmp = {:name=>nil, :family=>"windows", :release=>"Server 2012 R2", :arch=>nil} +if !compare_hash(local, cmp) || !compare_hash(winrm, cmp) + puts "Expected OS: #{cmp}" + exit 1 +end