fog-local 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ # Use so you can run in mock mode from the command line
2
+ #
3
+ # FOG_MOCK=true fog
4
+
5
+ if ENV["FOG_MOCK"] == "true"
6
+ Fog.mock!
7
+ end
@@ -0,0 +1,31 @@
1
+ def model_tests(collection, params = {}, mocks_implemented = true)
2
+ tests('success') do
3
+
4
+ @instance = collection.new(params)
5
+
6
+ tests("#save").succeeds do
7
+ pending if Fog.mocking? && !mocks_implemented
8
+ @instance.save
9
+ end
10
+
11
+ if block_given?
12
+ yield(@instance)
13
+ end
14
+
15
+ tests("#destroy").succeeds do
16
+ pending if Fog.mocking? && !mocks_implemented
17
+ @instance.destroy
18
+ end
19
+
20
+ end
21
+ end
22
+
23
+ # Generates a unique identifier with a random differentiator.
24
+ # Useful when rapidly re-running tests, so we don't have to wait
25
+ # serveral minutes for deleted objects to disappear from the API
26
+ # E.g. 'fog-test-1234'
27
+ def uniq_id(base_name = 'fog-test')
28
+ # random_differentiator
29
+ suffix = rand(65536).to_s(16).rjust(4, '0')
30
+ [base_name, suffix] * '-'
31
+ end
@@ -0,0 +1,107 @@
1
+ Shindo.tests('Fog::Schema::DataValidator', 'meta') do
2
+
3
+ validator = Fog::Schema::DataValidator.new
4
+
5
+ tests('#validate') do
6
+
7
+ tests('returns true') do
8
+
9
+ returns(true, 'when value matches schema expectation') do
10
+ validator.validate({"key" => "Value"}, {"key" => String})
11
+ end
12
+
13
+ returns(true, 'when values within an array all match schema expectation') do
14
+ validator.validate({"key" => [1, 2]}, {"key" => [Integer]})
15
+ end
16
+
17
+ returns(true, 'when nested values match schema expectation') do
18
+ validator.validate({"key" => {:nested_key => "Value"}}, {"key" => {:nested_key => String}})
19
+ end
20
+
21
+ returns(true, 'when collection of values all match schema expectation') do
22
+ validator.validate([{"key" => "Value"}, {"key" => "Value"}], [{"key" => String}])
23
+ end
24
+
25
+ returns(true, 'when collection is empty although schema covers optional members') do
26
+ validator.validate([], [{"key" => String}])
27
+ end
28
+
29
+ returns(true, 'when additional keys are passed and not strict') do
30
+ validator.validate({"key" => "Value", :extra => "Bonus"}, {"key" => String}, {:allow_extra_keys => true})
31
+ end
32
+
33
+ returns(true, 'when value is nil and schema expects NilClass') do
34
+ validator.validate({"key" => nil}, {"key" => NilClass})
35
+ end
36
+
37
+ returns(true, 'when value and schema match as hashes') do
38
+ validator.validate({}, {})
39
+ end
40
+
41
+ returns(true, 'when value and schema match as arrays') do
42
+ validator.validate([], [])
43
+ end
44
+
45
+ returns(true, 'when value is a Time') do
46
+ validator.validate({"time" => Time.now}, {"time" => Time})
47
+ end
48
+
49
+ returns(true, 'when key is missing but value should be NilClass (#1477)') do
50
+ validator.validate({}, {"key" => NilClass}, {:allow_optional_rules => true})
51
+ end
52
+
53
+ returns(true, 'when key is missing but value is nullable (#1477)') do
54
+ validator.validate({}, {"key" => Fog::Nullable::String}, {:allow_optional_rules => true})
55
+ end
56
+
57
+ end
58
+
59
+ tests('returns false') do
60
+
61
+ returns(false, 'when value does not match schema expectation') do
62
+ validator.validate({"key" => nil}, {"key" => String})
63
+ end
64
+
65
+ returns(false, 'when key formats do not match') do
66
+ validator.validate({"key" => "Value"}, {:key => String})
67
+ end
68
+
69
+ returns(false, 'when additional keys are passed and strict') do
70
+ validator.validate({"key" => "Missing"}, {})
71
+ end
72
+
73
+ returns(false, 'when some keys do not appear') do
74
+ validator.validate({}, {"key" => String})
75
+ end
76
+
77
+ returns(false, 'when collection contains a member that does not match schema') do
78
+ validator.validate([{"key" => "Value"}, {"key" => 5}], [{"key" => String}])
79
+ end
80
+
81
+ returns(false, 'when collection has multiple schema patterns') do
82
+ validator.validate([{"key" => "Value"}], [{"key" => Integer}, {"key" => String}])
83
+ end
84
+
85
+ returns(false, 'when hash and array are compared') do
86
+ validator.validate({}, [])
87
+ end
88
+
89
+ returns(false, 'when array and hash are compared') do
90
+ validator.validate([], {})
91
+ end
92
+
93
+ returns(false, 'when a hash is expected but another data type is found') do
94
+ validator.validate({"key" => {:nested_key => []}}, {"key" => {:nested_key => {}}})
95
+ end
96
+
97
+ returns(false, 'when key is missing but value should be NilClass (#1477)') do
98
+ validator.validate({}, {"key" => NilClass}, {:allow_optional_rules => false})
99
+ end
100
+
101
+ returns(false, 'when key is missing but value is nullable (#1477)') do
102
+ validator.validate({}, {"key" => Fog::Nullable::String}, {:allow_optional_rules => false})
103
+ end
104
+
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,9 @@
1
+ module Shindo
2
+ class Tests
3
+ def succeeds
4
+ test('succeeds') do
5
+ !!instance_eval(&Proc.new)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ Shindo.tests('Storage[:local] | directories', ["local"]) do
2
+
3
+ pending if Fog.mocking?
4
+
5
+ @options = { :local_root => "/tmp/fogtests" }
6
+ @collection = Fog::Storage::Local.new(@options).directories
7
+
8
+ collection_tests(@collection, {:key => "fogdirtests"}, true)
9
+
10
+ tests("#all") do
11
+ tests("succeeds when :local_root does not exist").succeeds do
12
+ FileUtils.rm_rf(@options[:local_root])
13
+ @collection.all
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,16 @@
1
+ Shindo.tests('Storage[:local] | directory', ["local"]) do
2
+
3
+ pending if Fog.mocking?
4
+
5
+ before do
6
+ @options = { :local_root => '~/.fog' }
7
+ end
8
+
9
+ tests('save') do
10
+ returns(true) do
11
+ connection = Fog::Storage::Local.new(@options)
12
+ connection.directories.create(:key => 'directory')
13
+ connection.directories.create(:key => 'directory')
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,43 @@
1
+ Shindo.tests('Storage[:local] | file', ["local"]) do
2
+
3
+ pending if Fog.mocking?
4
+
5
+ before do
6
+ @options = { :local_root => '~/.fog' }
7
+ end
8
+
9
+ tests('#public_url') do
10
+ tests('when connection has an endpoint').
11
+ returns('http://example.com/files/directory/file.txt') do
12
+ @options[:endpoint] = 'http://example.com/files'
13
+
14
+ connection = Fog::Storage::Local.new(@options)
15
+ directory = connection.directories.new(:key => 'directory')
16
+ file = directory.files.new(:key => 'file.txt')
17
+
18
+ file.public_url
19
+ end
20
+
21
+ tests('when connection has no endpoint').
22
+ returns(nil) do
23
+ @options[:endpoint] = nil
24
+
25
+ connection = Fog::Storage::Local.new(@options)
26
+ directory = connection.directories.new(:key => 'directory')
27
+ file = directory.files.new(:key => 'file.txt')
28
+
29
+ file.public_url
30
+ end
31
+
32
+ tests('when file path has escapable characters').
33
+ returns('http://example.com/files/my%20directory/my%20file.txt') do
34
+ @options[:endpoint] = 'http://example.com/files'
35
+
36
+ connection = Fog::Storage::Local.new(@options)
37
+ directory = connection.directories.new(:key => 'my directory')
38
+ file = directory.files.new(:key => 'my file.txt')
39
+
40
+ file.public_url
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,40 @@
1
+ Shindo.tests('Local | storage') do
2
+
3
+ pending if Fog.mocking?
4
+
5
+ before do
6
+ @options = { :local_root => "~/.fog" }
7
+ end
8
+
9
+ tests('#endpoint') do
10
+ tests('when no endpoint is provided').
11
+ returns(nil) do
12
+ Fog::Storage::Local.new(@options).endpoint
13
+ end
14
+
15
+ tests('when no host is provided').
16
+ returns(nil) do
17
+ @options[:scheme] = 'http'
18
+ @options[:path] = '/files'
19
+ @options[:port] = 80
20
+
21
+ Fog::Storage::Local.new(@options).endpoint
22
+ end
23
+
24
+ tests('when endpoint is provided').
25
+ returns('http://example.com/files') do
26
+ @options[:endpoint] = 'http://example.com/files'
27
+
28
+ Fog::Storage::Local.new(@options).endpoint
29
+ end
30
+
31
+ tests('when at least host option is provided').
32
+ returns('http://example.com/files') do
33
+ @options[:scheme] = 'http'
34
+ @options[:host] = 'example.com'
35
+ @options[:path] = '/files'
36
+
37
+ Fog::Storage::Local.new(@options).endpoint
38
+ end
39
+ end
40
+ end
data/tests/watchr.rb ADDED
@@ -0,0 +1,22 @@
1
+ ENV['FOG_MOCK'] ||= 'true'
2
+ ENV['AUTOTEST'] = 'true'
3
+ ENV['WATCHR'] = '1'
4
+
5
+ def file2shindo(file)
6
+ result = file.sub('lib/fog/', 'tests/').gsub(/\.rb$/, '_tests.rb')
7
+ end
8
+
9
+ def run_shindo_test(file)
10
+ if File.exist? file
11
+ system("shindont #{file}")
12
+ else
13
+ puts "FIXME: No test #{file} [#{Time.now}]"
14
+ end
15
+ end
16
+
17
+ watch( 'tests/.*_tests\.rb' ) do |md|
18
+ run_shindo_test(md[0])
19
+ end
20
+ watch( 'lib/.*\.rb' ) do |md|
21
+ run_shindo_test(file2shindo(md[0]))
22
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fog-local
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Wesley Beary
8
+ - Ville Lautanala
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-02-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.7'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.7'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: shindo
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '0.3'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '0.3'
56
+ - !ruby/object:Gem::Dependency
57
+ name: fog-core
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '1.27'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.27'
70
+ description: |-
71
+ This library can be used as a module for `fog` or as standalone provider
72
+ to use local filesystem storage.
73
+ email:
74
+ - geemus@gmail.com
75
+ - lautis@gmail.com
76
+ executables: []
77
+ extensions: []
78
+ extra_rdoc_files: []
79
+ files:
80
+ - ".gitignore"
81
+ - ".travis.yml"
82
+ - CONTRIBUTING.md
83
+ - CONTRIBUTORS.md
84
+ - Gemfile
85
+ - LICENSE.md
86
+ - README.md
87
+ - Rakefile
88
+ - fog-local.gemspec
89
+ - lib/fog-local.rb
90
+ - lib/fog/bin/local.rb
91
+ - lib/fog/local.rb
92
+ - lib/fog/local/core.rb
93
+ - lib/fog/local/models/storage/directories.rb
94
+ - lib/fog/local/models/storage/directory.rb
95
+ - lib/fog/local/models/storage/file.rb
96
+ - lib/fog/local/models/storage/files.rb
97
+ - lib/fog/local/storage.rb
98
+ - lib/fog/local/version.rb
99
+ - tests/helper.rb
100
+ - tests/helpers/collection_helper.rb
101
+ - tests/helpers/formats_helper.rb
102
+ - tests/helpers/formats_helper_tests.rb
103
+ - tests/helpers/mock_helper.rb
104
+ - tests/helpers/model_helper.rb
105
+ - tests/helpers/schema_validator_tests.rb
106
+ - tests/helpers/succeeds_helper.rb
107
+ - tests/local/models/directories_tests.rb
108
+ - tests/local/models/directory_tests.rb
109
+ - tests/local/models/file_tests.rb
110
+ - tests/local/storage_tests.rb
111
+ - tests/watchr.rb
112
+ homepage: https://github.com/fog/fog-local
113
+ licenses:
114
+ - MIT
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.4.5
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: Module for the 'fog' gem to support local filesystem storage.
136
+ test_files: []