diff --git a/Rakefile b/Rakefile index 0541e9fd..8fda9765 100644 --- a/Rakefile +++ b/Rakefile @@ -33,9 +33,10 @@ 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") + task :windows do + Dir.glob('test/windows/*_test.rb').all? do |file| + sh(Gem.ruby, '-w', '-Ilib:test', file) + end or fail 'Failures' end task :vm do diff --git a/appveyor.yml b/appveyor.yml index fde495f7..00c66d6d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -42,4 +42,4 @@ build_script: test_script: - SET SPEC_OPTS=--format progress - - bundle exec rake test:winrm + - bundle exec rake test:windows diff --git a/test/windows/local_test.rb b/test/windows/local_test.rb new file mode 100644 index 00000000..b176da55 --- /dev/null +++ b/test/windows/local_test.rb @@ -0,0 +1,34 @@ +# encoding: utf-8 +# author: Christoph Hartmann +# author: Dominik Richter + +require 'minitest/autorun' +require 'minitest/spec' +require 'mocha/setup' +require 'train' + +describe 'windows local command' do + let(:conn) { + # get final config + target_config = Train.target_config({}) + # initialize train + backend = Train.create('local', target_config) + + # start or reuse a connection + conn = backend.connection + conn + } + + it 'verify os' do + os = conn.os + os[:name].must_equal nil + os[:family].must_equal "windows" + os[:release].must_equal "Server 2012 R2" + os[:arch].must_equal nil + end + + after do + # close the connection + conn.close + end +end diff --git a/test/windows/winrm_test.rb b/test/windows/winrm_test.rb new file mode 100644 index 00000000..94084fe0 --- /dev/null +++ b/test/windows/winrm_test.rb @@ -0,0 +1,40 @@ +# encoding: utf-8 +# author: Christoph Hartmann +# author: Dominik Richter + +require 'minitest/autorun' +require 'minitest/spec' +require 'mocha/setup' +require 'train' + +describe 'windows local command' do + let(:conn) { + # get final config + target_config = Train.target_config({ + target: ENV['train_target'], + password: ENV['winrm_pass'], + ssl: ENV['train_ssl'], + self_signed: true, + }) + + # initialize train + backend = Train.create('winrm', target_config) + + # start or reuse a connection + conn = backend.connection + conn + } + + it 'verify os' do + os = conn.os + os[:name].must_equal nil + os[:family].must_equal "windows" + os[:release].must_equal "Server 2012 R2" + os[:arch].must_equal nil + end + + after do + # close the connection + conn.close + end +end diff --git a/test/winrm/windows.rb b/test/winrm/windows.rb deleted file mode 100644 index 6e3555e7..00000000 --- a/test/winrm/windows.rb +++ /dev/null @@ -1,62 +0,0 @@ -#!/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