winrm-fs 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,26 +1,26 @@
1
- # encoding: UTF-8
2
- require_relative '../../lib/winrm-fs/core/tmp_zip'
3
-
4
- describe WinRM::FS::Core::TmpZip do
5
- let(:winrm_fs_dir) { File.expand_path('../../lib/winrm-fs', File.dirname(__FILE__)) }
6
-
7
- subject { WinRM::FS::Core::TmpZip.new(winrm_fs_dir) }
8
-
9
- context 'temp file creation' do
10
- it 'should create a temp file on disk' do
11
- path = subject.path
12
- expect(File.exist?(path)).to be true
13
- subject.unlink
14
- expect(File.exist?(path)).to be false
15
- end
16
- end
17
-
18
- context 'create zip' do
19
- it 'should add all files in directory to the zip recursively' do
20
- expect(subject).to contain_zip_entries([
21
- 'exceptions.rb',
22
- 'core/tmp_zip.rb',
23
- 'scripts/checksum.ps1.erb'])
24
- end
25
- end
26
- end
1
+ # encoding: UTF-8
2
+ require_relative '../../lib/winrm-fs/core/tmp_zip'
3
+
4
+ describe WinRM::FS::Core::TmpZip do
5
+ let(:winrm_fs_dir) { File.expand_path('../../lib/winrm-fs', File.dirname(__FILE__)) }
6
+
7
+ subject { WinRM::FS::Core::TmpZip.new(winrm_fs_dir) }
8
+
9
+ context 'temp file creation' do
10
+ it 'should create a temp file on disk' do
11
+ path = subject.path
12
+ expect(File.exist?(path)).to be true
13
+ subject.unlink
14
+ expect(File.exist?(path)).to be false
15
+ end
16
+ end
17
+
18
+ context 'create zip' do
19
+ it 'should add all files in directory to the zip recursively' do
20
+ expect(subject).to contain_zip_entries([
21
+ 'exceptions.rb',
22
+ 'core/tmp_zip.rb',
23
+ 'scripts/checksum.ps1.erb'])
24
+ end
25
+ end
26
+ end
data/spec/matchers.rb CHANGED
@@ -1,58 +1,58 @@
1
- # encoding: UTF-8
2
- require 'rspec/expectations'
3
-
4
- RSpec::Matchers.define :have_created do |remote_file|
5
- match do |file_manager|
6
- if @expected_content
7
- downloaded_file = Tempfile.new('downloaded')
8
- downloaded_file.close
9
-
10
- subject.download(remote_file, downloaded_file.path)
11
- @actual_content = File.read(downloaded_file.path)
12
- downloaded_file.delete
13
-
14
- file_manager.exists?(remote_file) && \
15
- @actual_content == @expected_content
16
- else
17
- file_manager.exists?(remote_file)
18
- end
19
- end
20
- chain :with_content do |expected_content|
21
- expected_content = File.read(expected_content) if File.file?(expected_content)
22
- @expected_content = expected_content
23
- end
24
- failure_message do
25
- if @expected_content
26
- <<-EOH
27
- Expected file '#{remote_file}' to exist with content:
28
-
29
- #{@expected_content}
30
-
31
- but instead got content:
32
-
33
- #{@actual_content}
34
- EOH
35
- else
36
- "Expected file '#{remote_file}' to exist"
37
- end
38
- end
39
- end
40
-
41
- RSpec::Matchers.define :contain_zip_entries do |zip_entries|
42
- match do |temp_zip_file|
43
- zip_entries = [zip_entries] if zip_entries.is_a? String
44
- @zip_file = Zip::File.open(temp_zip_file.path)
45
- @missing_entries = []
46
- zip_entries.each do |entry|
47
- @missing_entries << entry unless @zip_file.find_entry(entry)
48
- end
49
- @missing_entries.empty?
50
- end
51
- failure_message do |temp_zip_file|
52
- msg = "Expected #{temp_zip_file.path} to contain zip entries: #{@missing_entries}\n Got: "
53
- @zip_file.each do |entry|
54
- msg << entry.name << ', '
55
- end
56
- msg
57
- end
58
- end
1
+ # encoding: UTF-8
2
+ require 'rspec/expectations'
3
+
4
+ RSpec::Matchers.define :have_created do |remote_file|
5
+ match do |file_manager|
6
+ if @expected_content
7
+ downloaded_file = Tempfile.new('downloaded')
8
+ downloaded_file.close
9
+
10
+ subject.download(remote_file, downloaded_file.path)
11
+ @actual_content = File.read(downloaded_file.path)
12
+ downloaded_file.delete
13
+
14
+ file_manager.exists?(remote_file) && \
15
+ @actual_content == @expected_content
16
+ else
17
+ file_manager.exists?(remote_file)
18
+ end
19
+ end
20
+ chain :with_content do |expected_content|
21
+ expected_content = File.read(expected_content) if File.file?(expected_content)
22
+ @expected_content = expected_content
23
+ end
24
+ failure_message do
25
+ if @expected_content
26
+ <<-EOH
27
+ Expected file '#{remote_file}' to exist with content:
28
+
29
+ #{@expected_content}
30
+
31
+ but instead got content:
32
+
33
+ #{@actual_content}
34
+ EOH
35
+ else
36
+ "Expected file '#{remote_file}' to exist"
37
+ end
38
+ end
39
+ end
40
+
41
+ RSpec::Matchers.define :contain_zip_entries do |zip_entries|
42
+ match do |temp_zip_file|
43
+ zip_entries = [zip_entries] if zip_entries.is_a? String
44
+ @zip_file = Zip::File.open(temp_zip_file.path)
45
+ @missing_entries = []
46
+ zip_entries.each do |entry|
47
+ @missing_entries << entry unless @zip_file.find_entry(entry)
48
+ end
49
+ @missing_entries.empty?
50
+ end
51
+ failure_message do |temp_zip_file|
52
+ msg = "Expected #{temp_zip_file.path} to contain zip entries: #{@missing_entries}\n Got: "
53
+ @zip_file.each do |entry|
54
+ msg << entry.name << ', '
55
+ end
56
+ msg
57
+ end
58
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,71 +1,71 @@
1
- # encoding: UTF-8
2
- require 'rubygems'
3
- require 'bundler/setup'
4
- require 'winrm-fs'
5
- require 'json'
6
- require_relative 'matchers'
7
-
8
- # Creates a WinRM connection for integration tests
9
- module ConnectionHelper
10
- # rubocop:disable AbcSize
11
- def winrm_connection
12
- WinRM::Connection.new(config)
13
- end
14
- # rubocop:enable AbcSize
15
-
16
- def config
17
- @config ||= begin
18
- cfg = symbolize_keys(YAML.load(File.read(winrm_config_path)))
19
- cfg.merge!(basic_auth_only: true) unless cfg[:transport].eql? :kerberos
20
- merge_environment!(cfg)
21
- cfg
22
- end
23
- end
24
-
25
- def merge_environment!(config)
26
- merge_config_option_from_environment(config, 'user')
27
- merge_config_option_from_environment(config, 'password')
28
- merge_config_option_from_environment(config, 'no_ssl_peer_verification')
29
- if ENV['use_ssl_peer_fingerprint']
30
- config[:options][:ssl_peer_fingerprint] = ENV['winrm_cert']
31
- end
32
- config[:endpoint] = ENV['winrm_endpoint'] if ENV['winrm_endpoint']
33
- config[:transport] = ENV['winrm_transport'] if ENV['winrm_transport']
34
- end
35
-
36
- def merge_config_option_from_environment(config, key)
37
- env_key = 'winrm_' + key
38
- config[key.to_sym] = ENV[env_key] if ENV[env_key]
39
- end
40
-
41
- def winrm_config_path
42
- # Copy config-example.yml to config.yml and edit for your local configuration
43
- path = File.expand_path("#{File.dirname(__FILE__)}/config.yml")
44
- unless File.exist?(path)
45
- # user hasn't done this, so use sane defaults for unit tests
46
- path = File.expand_path("#{File.dirname(__FILE__)}/config-example.yml")
47
- end
48
- path
49
- end
50
-
51
- # rubocop:disable Metrics/MethodLength
52
- def symbolize_keys(hash)
53
- hash.each_with_object({}) do |(key, value), result|
54
- new_key = case key
55
- when String then key.to_sym
56
- else key
57
- end
58
- new_value = case value
59
- when Hash then symbolize_keys(value)
60
- else value
61
- end
62
- result[new_key] = new_value
63
- result
64
- end
65
- end
66
- # rubocop:enable Metrics/MethodLength
67
- end
68
-
69
- RSpec.configure do |config|
70
- config.include(ConnectionHelper)
71
- end
1
+ # encoding: UTF-8
2
+ require 'rubygems'
3
+ require 'bundler/setup'
4
+ require 'winrm-fs'
5
+ require 'json'
6
+ require_relative 'matchers'
7
+
8
+ # Creates a WinRM connection for integration tests
9
+ module ConnectionHelper
10
+ # rubocop:disable AbcSize
11
+ def winrm_connection
12
+ WinRM::Connection.new(config)
13
+ end
14
+ # rubocop:enable AbcSize
15
+
16
+ def config
17
+ @config ||= begin
18
+ cfg = symbolize_keys(YAML.load(File.read(winrm_config_path)))
19
+ cfg.merge!(basic_auth_only: true) unless cfg[:transport].eql? :kerberos
20
+ merge_environment!(cfg)
21
+ cfg
22
+ end
23
+ end
24
+
25
+ def merge_environment!(config)
26
+ merge_config_option_from_environment(config, 'user')
27
+ merge_config_option_from_environment(config, 'password')
28
+ merge_config_option_from_environment(config, 'no_ssl_peer_verification')
29
+ if ENV['use_ssl_peer_fingerprint']
30
+ config[:options][:ssl_peer_fingerprint] = ENV['winrm_cert']
31
+ end
32
+ config[:endpoint] = ENV['winrm_endpoint'] if ENV['winrm_endpoint']
33
+ config[:transport] = ENV['winrm_transport'] if ENV['winrm_transport']
34
+ end
35
+
36
+ def merge_config_option_from_environment(config, key)
37
+ env_key = 'winrm_' + key
38
+ config[key.to_sym] = ENV[env_key] if ENV[env_key]
39
+ end
40
+
41
+ def winrm_config_path
42
+ # Copy config-example.yml to config.yml and edit for your local configuration
43
+ path = File.expand_path("#{File.dirname(__FILE__)}/config.yml")
44
+ unless File.exist?(path)
45
+ # user hasn't done this, so use sane defaults for unit tests
46
+ path = File.expand_path("#{File.dirname(__FILE__)}/config-example.yml")
47
+ end
48
+ path
49
+ end
50
+
51
+ # rubocop:disable Metrics/MethodLength
52
+ def symbolize_keys(hash)
53
+ hash.each_with_object({}) do |(key, value), result|
54
+ new_key = case key
55
+ when String then key.to_sym
56
+ else key
57
+ end
58
+ new_value = case value
59
+ when Hash then symbolize_keys(value)
60
+ else value
61
+ end
62
+ result[new_key] = new_value
63
+ result
64
+ end
65
+ end
66
+ # rubocop:enable Metrics/MethodLength
67
+ end
68
+
69
+ RSpec.configure do |config|
70
+ config.include(ConnectionHelper)
71
+ end
@@ -1,79 +1,79 @@
1
- # -*- encoding: utf-8 -*-
2
- #
3
- # Author:: Fletcher (<fnichol@nichol.ca>)
4
- #
5
- # Copyright (C) 2015, Fletcher Nichol
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the 'License');
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an 'AS IS' BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
-
19
- require 'winrm-fs/core/tmp_zip'
20
-
21
- describe WinRM::FS::Core::TmpZip do
22
- let(:src_dir) do
23
- tmpdir = Pathname.new(Dir.mktmpdir)
24
- @tmpdirs << tmpdir
25
- src_dir = tmpdir.join('src')
26
- sub_dir = src_dir.join('veggies')
27
-
28
- src_dir.mkpath
29
- create_local_file(src_dir.join('apple.txt'), 'appleapple')
30
- create_local_file(src_dir.join('banana.txt'), 'bananabanana')
31
- create_local_file(src_dir.join('cherry.txt'), 'cherrycherry')
32
- sub_dir.mkpath
33
- create_local_file(sub_dir.join('carrot.txt'), 'carrotcarrot')
34
- src_dir
35
- end
36
-
37
- let(:tmp_zip) { WinRM::FS::Core::TmpZip.new(src_dir) }
38
-
39
- before { @tmpdirs = [] }
40
-
41
- after do
42
- @tmpdirs.each(&:rmtree)
43
- tmp_zip.unlink if tmp_zip.path
44
- end
45
-
46
- it '#path returns path to created zip file' do
47
- expect(tmp_zip.path.file?).to eq true
48
- end
49
-
50
- it '#unlink removes the file' do
51
- path = tmp_zip.path
52
- expect(path.file?).to eq true
53
-
54
- tmp_zip.unlink
55
-
56
- expect(path.file?).to eq false
57
- expect(tmp_zip.path).to eq nil
58
- end
59
-
60
- describe 'for a zip file containing the base directory' do
61
- let(:tmp_zip) { WinRM::FS::Core::TmpZip.new(src_dir) }
62
-
63
- it 'contains the input entries' do
64
- zip = Zip::File.new(tmp_zip.path)
65
-
66
- expect(zip.map(&:name).sort).to eq(
67
- ['apple.txt', 'banana.txt', 'cherry.txt', 'veggies/carrot.txt']
68
- )
69
- expect(zip.read('apple.txt')).to eq 'appleapple'
70
- expect(zip.read('banana.txt')).to eq 'bananabanana'
71
- expect(zip.read('cherry.txt')).to eq 'cherrycherry'
72
- expect(zip.read('veggies/carrot.txt')).to eq 'carrotcarrot'
73
- end
74
- end
75
-
76
- def create_local_file(path, content)
77
- path.open('wb') { |file| file.write(content) }
78
- end
79
- end
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Fletcher (<fnichol@nichol.ca>)
4
+ #
5
+ # Copyright (C) 2015, Fletcher Nichol
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the 'License');
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an 'AS IS' BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ require 'winrm-fs/core/tmp_zip'
20
+
21
+ describe WinRM::FS::Core::TmpZip do
22
+ let(:src_dir) do
23
+ tmpdir = Pathname.new(Dir.mktmpdir)
24
+ @tmpdirs << tmpdir
25
+ src_dir = tmpdir.join('src')
26
+ sub_dir = src_dir.join('veggies')
27
+
28
+ src_dir.mkpath
29
+ create_local_file(src_dir.join('apple.txt'), 'appleapple')
30
+ create_local_file(src_dir.join('banana.txt'), 'bananabanana')
31
+ create_local_file(src_dir.join('cherry.txt'), 'cherrycherry')
32
+ sub_dir.mkpath
33
+ create_local_file(sub_dir.join('carrot.txt'), 'carrotcarrot')
34
+ src_dir
35
+ end
36
+
37
+ let(:tmp_zip) { WinRM::FS::Core::TmpZip.new(src_dir) }
38
+
39
+ before { @tmpdirs = [] }
40
+
41
+ after do
42
+ @tmpdirs.each(&:rmtree)
43
+ tmp_zip.unlink if tmp_zip.path
44
+ end
45
+
46
+ it '#path returns path to created zip file' do
47
+ expect(tmp_zip.path.file?).to eq true
48
+ end
49
+
50
+ it '#unlink removes the file' do
51
+ path = tmp_zip.path
52
+ expect(path.file?).to eq true
53
+
54
+ tmp_zip.unlink
55
+
56
+ expect(path.file?).to eq false
57
+ expect(tmp_zip.path).to eq nil
58
+ end
59
+
60
+ describe 'for a zip file containing the base directory' do
61
+ let(:tmp_zip) { WinRM::FS::Core::TmpZip.new(src_dir) }
62
+
63
+ it 'contains the input entries' do
64
+ zip = Zip::File.new(tmp_zip.path)
65
+
66
+ expect(zip.map(&:name).sort).to eq(
67
+ ['apple.txt', 'banana.txt', 'cherry.txt', 'veggies/carrot.txt']
68
+ )
69
+ expect(zip.read('apple.txt')).to eq 'appleapple'
70
+ expect(zip.read('banana.txt')).to eq 'bananabanana'
71
+ expect(zip.read('cherry.txt')).to eq 'cherrycherry'
72
+ expect(zip.read('veggies/carrot.txt')).to eq 'carrotcarrot'
73
+ end
74
+ end
75
+
76
+ def create_local_file(path, content)
77
+ path.open('wb') { |file| file.write(content) }
78
+ end
79
+ end