From 1f47b59ed7c60fbd45324add60741f97b967b84f Mon Sep 17 00:00:00 2001 From: Ted Wang Date: Wed, 23 Aug 2017 11:46:23 -0500 Subject: [PATCH] Local transport on Windows should use WindowsFile (#189) --- appveyor.yml | 1 + test/integration/tests/path_file_test.rb | 4 ++ test/windows/local_test.rb | 89 ++++++++++++++++++++++-- test/windows/winrm_test.rb | 81 +++++++++++++++++++-- 4 files changed, 162 insertions(+), 13 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 433fcfc8..71a430e6 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -38,6 +38,7 @@ install: - ps: winrm create winrm/config/Listener?Address=*+Transport=HTTPS "@{Hostname=`"localhost`";CertificateThumbprint=`"$($env:winrm_cert)`"}" - ps: $env:PATH="C:\Ruby$env:ruby_version\bin;$env:PATH" - ps: Write-Host $env:PATH + - ps: echo hello world > "C:\train_test_file" - ruby --version - gem --version - appveyor DownloadFile -Url %bundler_url% -FileName bundler.gem diff --git a/test/integration/tests/path_file_test.rb b/test/integration/tests/path_file_test.rb index db073380..754861bb 100644 --- a/test/integration/tests/path_file_test.rb +++ b/test/integration/tests/path_file_test.rb @@ -6,6 +6,10 @@ describe 'regular file' do let(:file) { backend.file('/tmp/file') } + it 'is a LinuxFile' do + file.must_be_kind_of(Train::Extras::LinuxFile) + end + it 'exists' do file.exist?.must_equal(true) end diff --git a/test/windows/local_test.rb b/test/windows/local_test.rb index 30c903e4..c07bb9b4 100644 --- a/test/windows/local_test.rb +++ b/test/windows/local_test.rb @@ -8,17 +8,21 @@ require 'train' describe 'windows local command' do - let(:conn) { + let(:backend) { # get final config - target_config = Train.target_config({}) - # initialize train - backend = Train.create('local', target_config) + target_config = Train.target_config({ + target: ENV['train_target'], + password: ENV['winrm_pass'], + ssl: ENV['train_ssl'], + self_signed: true, + }) - # start or reuse a connection - conn = backend.connection - conn + # initialize train + Train.create('winrm', target_config) } + let(:conn) { backend.connection } + it 'verify os' do os = conn.os os[:name].must_equal 'Windows Server 2012 R2 Datacenter' @@ -39,6 +43,77 @@ cmd.stderr.must_equal '' end + describe 'verify file' do + let(:file) { backend.file('C:\\train_test_file') } + + it 'is a WindowsFile' do + file.must_be_kind_of(Train::Extras::WindowsFile) + end + + it 'exists' do + file.exist?.must_equal(true) + end + + it 'is a file' do + file.file?.must_equal(true) + end + + it 'has type :file' do + file.type.must_equal(:file) + end + + it 'has content' do + file.content.must_equal('hello world') + end + + it 'has no owner name' do + file.owner.must_be_nil + end + + it 'has no group name' do + file.group.must_be_nil + end + + it 'has no mode' do + file.mode.must_be_nil + end + + it 'has an md5sum' do + file.md5sum.wont_be_nil + end + + it 'has an sha256sum' do + file.sha256sum.wont_be_nil + end + + it 'has no modified time' do + file.mtime.must_be_nil + end + + it 'has no size' do + # TODO: this really ought to be implemented + file.size.must_be_nil + end + + it 'has no selinux label handling' do + file.selinux_label.must_be_nil + end + + it 'has product_version' do + file.product_version.wont_be_nil + end + + it 'has file_version' do + file.file_version.wont_be_nil + end + + it 'provides a json representation' do + j = file.to_json + j.must_be_kind_of Hash + j['type'].must_equal :file + end + end + after do # close the connection conn.close diff --git a/test/windows/winrm_test.rb b/test/windows/winrm_test.rb index 37140b37..a5cb18da 100644 --- a/test/windows/winrm_test.rb +++ b/test/windows/winrm_test.rb @@ -8,7 +8,7 @@ require 'train' describe 'windows winrm command' do - let(:conn) { + let(:backend) { # get final config target_config = Train.target_config({ target: ENV['train_target'], @@ -18,13 +18,11 @@ }) # initialize train - backend = Train.create('winrm', target_config) - - # start or reuse a connection - conn = backend.connection - conn + Train.create('winrm', target_config) } + let(:conn) { backend.connection } + it 'verify os' do os = conn.os os[:name].must_equal 'Windows Server 2012 R2 Datacenter' @@ -45,6 +43,77 @@ cmd.stderr.must_equal '' end + describe 'verify file' do + let(:file) { backend.file('C:\\train_test_file') } + + it 'is an instance of WindowsFile' do + file.must_be_kind_of(Train::Extras::WindowsFile) + end + + it 'exists' do + file.exist?.must_equal(true) + end + + it 'is a file' do + file.file?.must_equal(true) + end + + it 'has type :file' do + file.type.must_equal(:file) + end + + it 'has content' do + file.content.must_equal('hello world') + end + + it 'has no owner name' do + file.owner.must_be_nil + end + + it 'has no group name' do + file.group.must_be_nil + end + + it 'has no mode' do + file.mode.must_be_nil + end + + it 'has an md5sum' do + file.md5sum.wont_be_nil + end + + it 'has an sha256sum' do + file.sha256sum.wont_be_nil + end + + it 'has no modified time' do + file.mtime.must_be_nil + end + + it 'has no size' do + # TODO: this really ought to be implemented + file.size.must_be_nil + end + + it 'has no selinux label handling' do + file.selinux_label.must_be_nil + end + + it 'has product_version' do + file.product_version.wont_be_nil + end + + it 'has file_version' do + file.file_version.wont_be_nil + end + + it 'provides a json representation' do + j = file.to_json + j.must_be_kind_of Hash + j['type'].must_equal :file + end + end + after do # close the connection conn.close