fog-local 0.3.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.github/dependabot.yml +10 -0
- data/.github/workflows/ruby.yml +34 -0
- data/.github/workflows/stale.yml +23 -0
- data/CONTRIBUTORS.md +1 -0
- data/README.md +5 -10
- data/fog-local.gemspec +3 -3
- data/lib/fog/bin/local.rb +2 -2
- data/lib/fog/local.rb +7 -7
- data/lib/fog/{storage/local → local}/models/directories.rb +10 -8
- data/lib/fog/{storage/local → local}/models/directory.rb +3 -8
- data/lib/fog/{storage/local → local}/models/file.rb +27 -12
- data/lib/fog/{storage/local → local}/models/files.rb +7 -3
- data/lib/fog/local/storage.rb +98 -1
- data/lib/fog/local/version.rb +1 -1
- data/tests/helper.rb +2 -1
- data/tests/helpers/succeeds_helper.rb +2 -2
- data/tests/local/models/directories_tests.rb +1 -1
- data/tests/local/models/directory_tests.rb +1 -1
- data/tests/local/models/file_tests.rb +70 -5
- data/tests/local/models/files_tests.rb +21 -0
- data/tests/local/storage_tests.rb +4 -4
- metadata +30 -27
- data/.ruby-version +0 -1
- data/.travis.yml +0 -14
- data/lib/fog/storage/local.rb +0 -98
- data/tests/helpers/formats_helper.rb +0 -98
- data/tests/helpers/formats_helper_tests.rb +0 -110
- data/tests/helpers/schema_validator_tests.rb +0 -107
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5059e832e9d246d3d6248701810c868c1a7b4bc77b4446ccefa888f511c894f3
|
4
|
+
data.tar.gz: 8c5968aae7995ca18bac5d9caa7c8b384b9146e8e888206fec8fcafbfc76dd00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d8aaf3d6c71a320f62fbd5477459bf288a96ce0adbb2bc4137543ba612f58ee4bcdb1cbc31c43345eb08154f1f84b6fb54384579eeb195b5ce343b9e5a0a2c0
|
7
|
+
data.tar.gz: 1df8b44a820c6434bfc2ffaea43388ec38968cf5aabc81304b3a4bb45db7e540bdc8479760f8eba86e2cbfda255adc5ba4583219244f931ba46e6442cd108968
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ master ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ master ]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
|
19
|
+
runs-on: ubuntu-latest
|
20
|
+
strategy:
|
21
|
+
matrix:
|
22
|
+
ruby-version: ['2.5', '2.6', '2.7', '3.0', 'head']
|
23
|
+
|
24
|
+
steps:
|
25
|
+
- uses: actions/checkout@v2
|
26
|
+
- name: Set up Ruby
|
27
|
+
uses: ruby/setup-ruby@v1
|
28
|
+
with:
|
29
|
+
ruby-version: ${{ matrix.ruby-version }}
|
30
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
31
|
+
- name: Install dependencies
|
32
|
+
run: bundle install
|
33
|
+
- name: Run tests
|
34
|
+
run: bundle exec rake
|
@@ -0,0 +1,23 @@
|
|
1
|
+
name: Mark stale issues and pull requests
|
2
|
+
|
3
|
+
on:
|
4
|
+
schedule:
|
5
|
+
- cron: "30 1 * * *"
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
stale:
|
9
|
+
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
|
12
|
+
steps:
|
13
|
+
- uses: actions/stale@v3
|
14
|
+
with:
|
15
|
+
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
16
|
+
days-before-stale: 60
|
17
|
+
days-before-close: 7
|
18
|
+
exempt-issue-labels: 'pinned,security'
|
19
|
+
exempt-pr-labels: 'pinned,security'
|
20
|
+
stale-issue-message: 'This issue has been marked inactive and will be closed if no further activity occurs.'
|
21
|
+
stale-pr-message: 'This pr has been marked inactive and will be closed if no further activity occurs.'
|
22
|
+
stale-issue-label: 'no-issue-activity'
|
23
|
+
stale-pr-label: 'no-pr-activity'
|
data/CONTRIBUTORS.md
CHANGED
data/README.md
CHANGED
@@ -22,27 +22,22 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
Initialise a `Fog::Storage` object
|
25
|
+
Initialise a `Fog::Local::Storage` object:
|
26
26
|
|
27
27
|
```ruby
|
28
|
-
|
29
|
-
storage = Fog::Storage.new({
|
30
|
-
:local_root => '~/fog',
|
31
|
-
:provider => 'Local'
|
32
|
-
})
|
33
|
-
|
28
|
+
storage = Fog::Local::Storage.new(local_root: '~/fog')
|
34
29
|
```
|
35
30
|
|
36
31
|
This can then be used like any other [Fog storage](http://fog.io/storage/).
|
37
32
|
|
38
33
|
```ruby
|
39
|
-
directory = storage.directories.create(:
|
40
|
-
directory.files.create(:
|
34
|
+
directory = storage.directories.create(key: 'data')
|
35
|
+
directory.files.create(body: 'Hello World!', key: 'hello_world.txt')
|
41
36
|
```
|
42
37
|
|
43
38
|
## Contributing
|
44
39
|
|
45
|
-
1. Fork it ( https://github.com/fog/fog-local/fork
|
40
|
+
1. Fork it ( https://github.com/fog/fog-local/fork)
|
46
41
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
47
42
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
48
43
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/fog-local.gemspec
CHANGED
@@ -19,9 +19,9 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_development_dependency 'bundler'
|
23
|
-
spec.add_development_dependency 'rake', '
|
22
|
+
spec.add_development_dependency 'bundler'
|
23
|
+
spec.add_development_dependency 'rake', '>= 12.3.3'
|
24
24
|
spec.add_development_dependency 'shindo', '~> 0.3'
|
25
25
|
|
26
|
-
spec.add_dependency 'fog-core', '
|
26
|
+
spec.add_dependency 'fog-core', '>= 1.27', '< 3.0'
|
27
27
|
end
|
data/lib/fog/bin/local.rb
CHANGED
@@ -3,7 +3,7 @@ class Local < Fog::Bin
|
|
3
3
|
def class_for(key)
|
4
4
|
case key
|
5
5
|
when :storage
|
6
|
-
Fog::Storage
|
6
|
+
Fog::Local::Storage
|
7
7
|
else
|
8
8
|
raise ArgumentError, "Unsupported #{self} service: #{key}"
|
9
9
|
end
|
@@ -14,7 +14,7 @@ class Local < Fog::Bin
|
|
14
14
|
hash[key] = case key
|
15
15
|
when :storage
|
16
16
|
Fog::Logger.warning("Local[:storage] is not recommended, use Storage[:local] for portability")
|
17
|
-
Fog::Storage.new
|
17
|
+
Fog::Local::Storage.new
|
18
18
|
else
|
19
19
|
raise ArgumentError, "Unrecognized service: #{key.inspect}"
|
20
20
|
end
|
data/lib/fog/local.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
require 'fog/core'
|
2
2
|
require 'fileutils'
|
3
3
|
require 'tempfile'
|
4
|
-
require File.expand_path('../local/version', __FILE__)
|
5
4
|
|
6
|
-
|
7
|
-
module Storage
|
8
|
-
autoload :Local, File.expand_path('../storage/local', __FILE__)
|
9
|
-
end
|
5
|
+
require 'fog/local/version'
|
10
6
|
|
7
|
+
module Fog
|
11
8
|
module Local
|
12
|
-
extend
|
9
|
+
extend Provider
|
13
10
|
|
14
|
-
|
11
|
+
autoload :Storage, 'fog/local/storage'
|
12
|
+
service :storage, :Storage
|
15
13
|
end
|
16
14
|
end
|
15
|
+
|
16
|
+
Fog::Storage::Local = Fog::Local::Storage # legacy compat
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Fog
|
2
|
-
module
|
3
|
-
class
|
2
|
+
module Local
|
3
|
+
class Storage
|
4
4
|
class Directories < Fog::Collection
|
5
|
-
model
|
5
|
+
model Directory
|
6
6
|
|
7
7
|
def all
|
8
8
|
data = if ::File.directory?(service.local_root)
|
@@ -18,11 +18,13 @@ module Fog
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def get(key, options = {})
|
21
|
-
if ::File.directory?(service.path_to(key))
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
create_directory(key, options) if ::File.directory?(service.path_to(key))
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def create_directory(key, options)
|
27
|
+
options[:path] ? new(key: key + options[:path]) : new(key: key)
|
26
28
|
end
|
27
29
|
end
|
28
30
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Fog
|
2
|
-
module
|
3
|
-
class
|
2
|
+
module Local
|
3
|
+
class Storage
|
4
4
|
class Directory < Fog::Model
|
5
5
|
identity :key
|
6
6
|
|
@@ -16,12 +16,7 @@ module Fog
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def files
|
19
|
-
@files ||=
|
20
|
-
Fog::Storage::Local::Files.new(
|
21
|
-
:directory => self,
|
22
|
-
:service => service
|
23
|
-
)
|
24
|
-
end
|
19
|
+
@files ||= Files.new(directory: self, service: service)
|
25
20
|
end
|
26
21
|
|
27
22
|
def public=(new_public)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Fog
|
2
|
-
module
|
3
|
-
class
|
2
|
+
module Local
|
3
|
+
class Storage
|
4
4
|
class File < Fog::Model
|
5
5
|
identity :key, :aliases => 'Key'
|
6
6
|
|
@@ -54,14 +54,7 @@ module Fog
|
|
54
54
|
if dir_path == service.path_to(directory.key)
|
55
55
|
break
|
56
56
|
end
|
57
|
-
|
58
|
-
if ::File.directory?(dir_path)
|
59
|
-
Dir.chdir(dir_path)
|
60
|
-
if Dir.glob('*').empty?
|
61
|
-
Dir.rmdir(dir_path)
|
62
|
-
end
|
63
|
-
Dir.chdir(pwd)
|
64
|
-
end
|
57
|
+
rm_if_empty_dir(dir_path)
|
65
58
|
end
|
66
59
|
true
|
67
60
|
end
|
@@ -74,8 +67,8 @@ module Fog
|
|
74
67
|
requires :directory, :key
|
75
68
|
|
76
69
|
if service.endpoint
|
77
|
-
escaped_directory =
|
78
|
-
escaped_key =
|
70
|
+
escaped_directory = uri_escape(directory.key)
|
71
|
+
escaped_key = uri_escape(key)
|
79
72
|
|
80
73
|
::File.join(service.endpoint, escaped_directory, escaped_key)
|
81
74
|
else
|
@@ -113,6 +106,12 @@ module Fog
|
|
113
106
|
@directory = new_directory
|
114
107
|
end
|
115
108
|
|
109
|
+
def uri_escape(string)
|
110
|
+
string.b.gsub(/([^a-zA-Z0-9_.\-~]+)/) do |m|
|
111
|
+
'%' + m.unpack('H2' * m.bytesize).join('%').upcase
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
116
115
|
def path
|
117
116
|
service.path_to(::File.join(directory.key, key))
|
118
117
|
end
|
@@ -125,6 +124,22 @@ module Fog
|
|
125
124
|
IO.copy_stream(input_io, file)
|
126
125
|
end
|
127
126
|
end
|
127
|
+
|
128
|
+
def rm_if_empty_dir(dir_path)
|
129
|
+
if ::File.directory?(dir_path)
|
130
|
+
Dir.rmdir(dir_path) if dir_empty?(dir_path)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def dir_empty?(dir_path)
|
135
|
+
# NOTE: There’s Dir.empty?, but it is only available on Ruby 2.4+
|
136
|
+
|
137
|
+
# NOTE: `entries` will be empty on Windows, and contain . and .. on
|
138
|
+
# unix-like systems (macOS, Linux, BSD, …)
|
139
|
+
|
140
|
+
entries = Dir.entries(dir_path)
|
141
|
+
entries.empty? || entries.all? { |e| ['.', '..'].include?(e) }
|
142
|
+
end
|
128
143
|
end
|
129
144
|
end
|
130
145
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module Fog
|
2
|
-
module
|
3
|
-
class
|
2
|
+
module Local
|
3
|
+
class Storage
|
4
4
|
class Files < Fog::Collection
|
5
5
|
attribute :directory
|
6
6
|
|
7
|
-
model
|
7
|
+
model File
|
8
8
|
|
9
9
|
def all
|
10
10
|
requires :directory
|
@@ -71,6 +71,10 @@ module Fog
|
|
71
71
|
super({ :directory => directory }.merge!(attributes))
|
72
72
|
end
|
73
73
|
|
74
|
+
def is_truncated
|
75
|
+
false
|
76
|
+
end
|
77
|
+
|
74
78
|
private
|
75
79
|
|
76
80
|
def file_path(key)
|
data/lib/fog/local/storage.rb
CHANGED
@@ -1 +1,98 @@
|
|
1
|
-
|
1
|
+
module Fog
|
2
|
+
module Local
|
3
|
+
class Storage < Fog::Service
|
4
|
+
autoload :Directories, 'fog/local/models/directories'
|
5
|
+
autoload :Directory, 'fog/local/models/directory'
|
6
|
+
autoload :File, 'fog/local/models/file'
|
7
|
+
autoload :Files, 'fog/local/models/files'
|
8
|
+
|
9
|
+
requires :local_root
|
10
|
+
recognizes :endpoint, :scheme, :host, :port, :path
|
11
|
+
|
12
|
+
model_path 'fog/local/models'
|
13
|
+
collection :directories
|
14
|
+
model :directory
|
15
|
+
model :file
|
16
|
+
collection :files
|
17
|
+
|
18
|
+
require 'uri'
|
19
|
+
|
20
|
+
class Mock
|
21
|
+
attr_reader :endpoint
|
22
|
+
|
23
|
+
def self.data
|
24
|
+
@data ||= Hash.new do |hash, key|
|
25
|
+
hash[key] = {}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.reset
|
30
|
+
@data = nil
|
31
|
+
end
|
32
|
+
|
33
|
+
def initialize(options={})
|
34
|
+
Fog::Mock.not_implemented
|
35
|
+
|
36
|
+
@local_root = ::File.expand_path(options[:local_root])
|
37
|
+
|
38
|
+
@endpoint = options[:endpoint] || build_endpoint_from_options(options)
|
39
|
+
end
|
40
|
+
|
41
|
+
def data
|
42
|
+
self.class.data[@local_root]
|
43
|
+
end
|
44
|
+
|
45
|
+
def local_root
|
46
|
+
@local_root
|
47
|
+
end
|
48
|
+
|
49
|
+
def path_to(partial)
|
50
|
+
::File.join(@local_root, partial)
|
51
|
+
end
|
52
|
+
|
53
|
+
def reset_data
|
54
|
+
self.class.data.delete(@local_root)
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
def build_endpoint_from_options(options)
|
59
|
+
return unless options[:host]
|
60
|
+
|
61
|
+
URI::Generic.build(options).to_s
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class Real
|
66
|
+
attr_reader :endpoint
|
67
|
+
|
68
|
+
def initialize(options={})
|
69
|
+
@local_root = ::File.expand_path(options[:local_root])
|
70
|
+
|
71
|
+
@endpoint = options[:endpoint] || build_endpoint_from_options(options)
|
72
|
+
end
|
73
|
+
|
74
|
+
def local_root
|
75
|
+
@local_root
|
76
|
+
end
|
77
|
+
|
78
|
+
def path_to(partial)
|
79
|
+
::File.join(@local_root, partial)
|
80
|
+
end
|
81
|
+
|
82
|
+
def copy_object(source_directory_name, source_object_name, target_directory_name, target_object_name, options={})
|
83
|
+
source_path = path_to(::File.join(source_directory_name, source_object_name))
|
84
|
+
target_path = path_to(::File.join(target_directory_name, target_object_name))
|
85
|
+
::FileUtils.mkdir_p(::File.dirname(target_path))
|
86
|
+
::FileUtils.copy_file(source_path, target_path)
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
def build_endpoint_from_options(options)
|
91
|
+
return unless options[:host]
|
92
|
+
|
93
|
+
URI::Generic.build(options).to_s
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
data/lib/fog/local/version.rb
CHANGED
data/tests/helper.rb
CHANGED
@@ -5,7 +5,8 @@ rescue LoadError => e
|
|
5
5
|
$stderr.puts "not recording test coverage: #{e.inspect}"
|
6
6
|
end
|
7
7
|
|
8
|
-
|
8
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
9
|
+
require 'fog/local'
|
9
10
|
|
10
11
|
Bundler.require(:test)
|
11
12
|
require 'tmpdir'
|
@@ -3,7 +3,7 @@ Shindo.tests('Storage[:local] | directories', ["local"]) do
|
|
3
3
|
pending if Fog.mocking?
|
4
4
|
|
5
5
|
@options = { :local_root => Dir.mktmpdir('fog-tests') }
|
6
|
-
@collection = Fog::Storage
|
6
|
+
@collection = Fog::Local::Storage.new(@options).directories
|
7
7
|
|
8
8
|
collection_tests(@collection, {:key => "fogdirtests"}, true)
|
9
9
|
|
@@ -12,7 +12,7 @@ Shindo.tests('Storage[:local] | directory', ["local"]) do
|
|
12
12
|
|
13
13
|
tests('save') do
|
14
14
|
returns('directory') do
|
15
|
-
connection = Fog::Storage
|
15
|
+
connection = Fog::Local::Storage.new(@options)
|
16
16
|
connection.directories.create(:key => 'directory')
|
17
17
|
connection.directories.create(:key => 'directory').key
|
18
18
|
end
|
@@ -15,7 +15,7 @@ Shindo.tests('Storage[:local] | file', ["local"]) do
|
|
15
15
|
returns('http://example.com/files/directory/file.txt') do
|
16
16
|
@options[:endpoint] = 'http://example.com/files'
|
17
17
|
|
18
|
-
connection = Fog::Storage
|
18
|
+
connection = Fog::Local::Storage.new(@options)
|
19
19
|
directory = connection.directories.new(:key => 'directory')
|
20
20
|
file = directory.files.new(:key => 'file.txt')
|
21
21
|
|
@@ -26,7 +26,7 @@ Shindo.tests('Storage[:local] | file', ["local"]) do
|
|
26
26
|
returns(nil) do
|
27
27
|
@options[:endpoint] = nil
|
28
28
|
|
29
|
-
connection = Fog::Storage
|
29
|
+
connection = Fog::Local::Storage.new(@options)
|
30
30
|
directory = connection.directories.new(:key => 'directory')
|
31
31
|
file = directory.files.new(:key => 'file.txt')
|
32
32
|
|
@@ -37,7 +37,7 @@ Shindo.tests('Storage[:local] | file', ["local"]) do
|
|
37
37
|
returns('http://example.com/files/my%20directory/my%20file.txt') do
|
38
38
|
@options[:endpoint] = 'http://example.com/files'
|
39
39
|
|
40
|
-
connection = Fog::Storage
|
40
|
+
connection = Fog::Local::Storage.new(@options)
|
41
41
|
directory = connection.directories.new(:key => 'my directory')
|
42
42
|
file = directory.files.new(:key => 'my file.txt')
|
43
43
|
|
@@ -48,7 +48,7 @@ Shindo.tests('Storage[:local] | file', ["local"]) do
|
|
48
48
|
tests('#save') do
|
49
49
|
tests('creates non-existent subdirs') do
|
50
50
|
returns(true) do
|
51
|
-
connection = Fog::Storage
|
51
|
+
connection = Fog::Local::Storage.new(@options)
|
52
52
|
directory = connection.directories.new(:key => 'path1')
|
53
53
|
file = directory.files.new(:key => 'path2/file.rb', :body => "my contents")
|
54
54
|
file.save
|
@@ -57,7 +57,7 @@ Shindo.tests('Storage[:local] | file', ["local"]) do
|
|
57
57
|
end
|
58
58
|
|
59
59
|
tests('with tempfile').returns('tempfile') do
|
60
|
-
connection = Fog::Storage
|
60
|
+
connection = Fog::Local::Storage.new(@options)
|
61
61
|
directory = connection.directories.create(:key => 'directory')
|
62
62
|
|
63
63
|
tempfile = Tempfile.new(['file', '.txt'])
|
@@ -76,4 +76,69 @@ Shindo.tests('Storage[:local] | file', ["local"]) do
|
|
76
76
|
directory.files.get('tempfile.txt').body
|
77
77
|
end
|
78
78
|
end
|
79
|
+
|
80
|
+
tests('#destroy') do
|
81
|
+
# - removes dir if it contains no files
|
82
|
+
# - keeps dir if it contains non-hidden files
|
83
|
+
# - keeps dir if it contains hidden files
|
84
|
+
# - stays in the same directory
|
85
|
+
|
86
|
+
tests('removes enclosing dir if it is empty') do
|
87
|
+
returns(false) do
|
88
|
+
connection = Fog::Local::Storage.new(@options)
|
89
|
+
directory = connection.directories.new(:key => 'path1')
|
90
|
+
|
91
|
+
file = directory.files.new(:key => 'path2/file.rb', :body => "my contents")
|
92
|
+
file.save
|
93
|
+
file.destroy
|
94
|
+
|
95
|
+
File.exists?(@options[:local_root] + "/path1/path2")
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
tests('keeps enclosing dir if it is not empty') do
|
100
|
+
returns(true) do
|
101
|
+
connection = Fog::Local::Storage.new(@options)
|
102
|
+
directory = connection.directories.new(:key => 'path1')
|
103
|
+
|
104
|
+
file = directory.files.new(:key => 'path2/file.rb', :body => "my contents")
|
105
|
+
file.save
|
106
|
+
|
107
|
+
file = directory.files.new(:key => 'path2/file2.rb', :body => "my contents")
|
108
|
+
file.save
|
109
|
+
file.destroy
|
110
|
+
|
111
|
+
File.exists?(@options[:local_root] + "/path1/path2")
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
tests('keeps enclosing dir if contains only hidden files') do
|
116
|
+
returns(true) do
|
117
|
+
connection = Fog::Local::Storage.new(@options)
|
118
|
+
directory = connection.directories.new(:key => 'path1')
|
119
|
+
|
120
|
+
file = directory.files.new(:key => 'path2/.file.rb', :body => "my contents")
|
121
|
+
file.save
|
122
|
+
|
123
|
+
file = directory.files.new(:key => 'path2/.file2.rb', :body => "my contents")
|
124
|
+
file.save
|
125
|
+
file.destroy
|
126
|
+
|
127
|
+
File.exists?(@options[:local_root] + "/path1/path2")
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
tests('it stays in the same directory') do
|
132
|
+
returns(Dir.pwd) do
|
133
|
+
connection = Fog::Local::Storage.new(@options)
|
134
|
+
directory = connection.directories.new(:key => 'path1')
|
135
|
+
|
136
|
+
file = directory.files.new(:key => 'path2/file2.rb', :body => "my contents")
|
137
|
+
file.save
|
138
|
+
file.destroy
|
139
|
+
|
140
|
+
Dir.pwd
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
79
144
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
Shindo.tests('Storage[:local] | files', ["local"]) do
|
2
|
+
|
3
|
+
pending if Fog.mocking?
|
4
|
+
|
5
|
+
before do
|
6
|
+
@options = { :local_root => Dir.mktmpdir('fog-tests') }
|
7
|
+
end
|
8
|
+
|
9
|
+
after do
|
10
|
+
FileUtils.remove_entry_secure(@options[:local_root]) if File.directory?(@options[:local_root])
|
11
|
+
end
|
12
|
+
|
13
|
+
tests("#is_truncated") do
|
14
|
+
returns(false) do
|
15
|
+
connection = Fog::Local::Storage.new(@options)
|
16
|
+
directory = connection.directories.create(:key => 'directory')
|
17
|
+
collection = directory.files
|
18
|
+
collection.is_truncated
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -13,7 +13,7 @@ Shindo.tests('Local | storage') do
|
|
13
13
|
tests('#endpoint') do
|
14
14
|
tests('when no endpoint is provided').
|
15
15
|
returns(nil) do
|
16
|
-
Fog::Storage
|
16
|
+
Fog::Local::Storage.new(@options).endpoint
|
17
17
|
end
|
18
18
|
|
19
19
|
tests('when no host is provided').
|
@@ -22,14 +22,14 @@ Shindo.tests('Local | storage') do
|
|
22
22
|
@options[:path] = '/files'
|
23
23
|
@options[:port] = 80
|
24
24
|
|
25
|
-
Fog::Storage
|
25
|
+
Fog::Local::Storage.new(@options).endpoint
|
26
26
|
end
|
27
27
|
|
28
28
|
tests('when endpoint is provided').
|
29
29
|
returns('http://example.com/files') do
|
30
30
|
@options[:endpoint] = 'http://example.com/files'
|
31
31
|
|
32
|
-
Fog::Storage
|
32
|
+
Fog::Local::Storage.new(@options).endpoint
|
33
33
|
end
|
34
34
|
|
35
35
|
tests('when at least host option is provided').
|
@@ -38,7 +38,7 @@ Shindo.tests('Local | storage') do
|
|
38
38
|
@options[:host] = 'example.com'
|
39
39
|
@options[:path] = '/files'
|
40
40
|
|
41
|
-
Fog::Storage
|
41
|
+
Fog::Local::Storage.new(@options).endpoint
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
metadata
CHANGED
@@ -1,44 +1,44 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fog-local
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wesley Beary
|
8
8
|
- Ville Lautanala
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-07-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - "
|
18
|
+
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
20
|
+
version: '0'
|
21
21
|
type: :development
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- - "
|
25
|
+
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: '
|
27
|
+
version: '0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rake
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- - "
|
32
|
+
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
34
|
+
version: 12.3.3
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- - "
|
39
|
+
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
41
|
+
version: 12.3.3
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: shindo
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -57,16 +57,22 @@ dependencies:
|
|
57
57
|
name: fog-core
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- - "
|
60
|
+
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '1.27'
|
63
|
+
- - "<"
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '3.0'
|
63
66
|
type: :runtime
|
64
67
|
prerelease: false
|
65
68
|
version_requirements: !ruby/object:Gem::Requirement
|
66
69
|
requirements:
|
67
|
-
- - "
|
70
|
+
- - ">="
|
68
71
|
- !ruby/object:Gem::Version
|
69
72
|
version: '1.27'
|
73
|
+
- - "<"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
70
76
|
description: |-
|
71
77
|
This library can be used as a module for `fog` or as standalone provider
|
72
78
|
to use local filesystem storage.
|
@@ -77,10 +83,11 @@ executables: []
|
|
77
83
|
extensions: []
|
78
84
|
extra_rdoc_files: []
|
79
85
|
files:
|
86
|
+
- ".github/dependabot.yml"
|
87
|
+
- ".github/workflows/ruby.yml"
|
88
|
+
- ".github/workflows/stale.yml"
|
80
89
|
- ".gitignore"
|
81
90
|
- ".ruby-gemset"
|
82
|
-
- ".ruby-version"
|
83
|
-
- ".travis.yml"
|
84
91
|
- CONTRIBUTING.md
|
85
92
|
- CONTRIBUTORS.md
|
86
93
|
- Gemfile
|
@@ -90,31 +97,28 @@ files:
|
|
90
97
|
- fog-local.gemspec
|
91
98
|
- lib/fog/bin/local.rb
|
92
99
|
- lib/fog/local.rb
|
100
|
+
- lib/fog/local/models/directories.rb
|
101
|
+
- lib/fog/local/models/directory.rb
|
102
|
+
- lib/fog/local/models/file.rb
|
103
|
+
- lib/fog/local/models/files.rb
|
93
104
|
- lib/fog/local/storage.rb
|
94
105
|
- lib/fog/local/version.rb
|
95
|
-
- lib/fog/storage/local.rb
|
96
|
-
- lib/fog/storage/local/models/directories.rb
|
97
|
-
- lib/fog/storage/local/models/directory.rb
|
98
|
-
- lib/fog/storage/local/models/file.rb
|
99
|
-
- lib/fog/storage/local/models/files.rb
|
100
106
|
- tests/helper.rb
|
101
107
|
- tests/helpers/collection_helper.rb
|
102
|
-
- tests/helpers/formats_helper.rb
|
103
|
-
- tests/helpers/formats_helper_tests.rb
|
104
108
|
- tests/helpers/mock_helper.rb
|
105
109
|
- tests/helpers/model_helper.rb
|
106
|
-
- tests/helpers/schema_validator_tests.rb
|
107
110
|
- tests/helpers/succeeds_helper.rb
|
108
111
|
- tests/local/models/directories_tests.rb
|
109
112
|
- tests/local/models/directory_tests.rb
|
110
113
|
- tests/local/models/file_tests.rb
|
114
|
+
- tests/local/models/files_tests.rb
|
111
115
|
- tests/local/storage_tests.rb
|
112
116
|
- tests/watchr.rb
|
113
117
|
homepage: https://github.com/fog/fog-local
|
114
118
|
licenses:
|
115
119
|
- MIT
|
116
120
|
metadata: {}
|
117
|
-
post_install_message:
|
121
|
+
post_install_message:
|
118
122
|
rdoc_options: []
|
119
123
|
require_paths:
|
120
124
|
- lib
|
@@ -129,9 +133,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
133
|
- !ruby/object:Gem::Version
|
130
134
|
version: '0'
|
131
135
|
requirements: []
|
132
|
-
|
133
|
-
|
134
|
-
signing_key:
|
136
|
+
rubygems_version: 3.2.15
|
137
|
+
signing_key:
|
135
138
|
specification_version: 4
|
136
139
|
summary: Module for the 'fog' gem to support local filesystem storage.
|
137
140
|
test_files: []
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.2.0
|
data/.travis.yml
DELETED
data/lib/fog/storage/local.rb
DELETED
@@ -1,98 +0,0 @@
|
|
1
|
-
module Fog
|
2
|
-
module Storage
|
3
|
-
class Local < Fog::Service
|
4
|
-
autoload :Directories, ::File.expand_path('../local/models/directories', __FILE__)
|
5
|
-
autoload :Directory, ::File.expand_path('../local/models/directory', __FILE__)
|
6
|
-
autoload :File, ::File.expand_path('../local/models/file', __FILE__)
|
7
|
-
autoload :Files, ::File.expand_path('../local/models/files', __FILE__)
|
8
|
-
|
9
|
-
requires :local_root
|
10
|
-
recognizes :endpoint, :scheme, :host, :port, :path
|
11
|
-
|
12
|
-
model_path 'fog/storage/local/models'
|
13
|
-
collection :directories
|
14
|
-
model :directory
|
15
|
-
model :file
|
16
|
-
collection :files
|
17
|
-
|
18
|
-
require 'uri'
|
19
|
-
|
20
|
-
class Mock
|
21
|
-
attr_reader :endpoint
|
22
|
-
|
23
|
-
def self.data
|
24
|
-
@data ||= Hash.new do |hash, key|
|
25
|
-
hash[key] = {}
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.reset
|
30
|
-
@data = nil
|
31
|
-
end
|
32
|
-
|
33
|
-
def initialize(options={})
|
34
|
-
Fog::Mock.not_implemented
|
35
|
-
|
36
|
-
@local_root = ::File.expand_path(options[:local_root])
|
37
|
-
|
38
|
-
@endpoint = options[:endpoint] || build_endpoint_from_options(options)
|
39
|
-
end
|
40
|
-
|
41
|
-
def data
|
42
|
-
self.class.data[@local_root]
|
43
|
-
end
|
44
|
-
|
45
|
-
def local_root
|
46
|
-
@local_root
|
47
|
-
end
|
48
|
-
|
49
|
-
def path_to(partial)
|
50
|
-
::File.join(@local_root, partial)
|
51
|
-
end
|
52
|
-
|
53
|
-
def reset_data
|
54
|
-
self.class.data.delete(@local_root)
|
55
|
-
end
|
56
|
-
|
57
|
-
private
|
58
|
-
def build_endpoint_from_options(options)
|
59
|
-
return unless options[:host]
|
60
|
-
|
61
|
-
URI::Generic.build(options).to_s
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
class Real
|
66
|
-
attr_reader :endpoint
|
67
|
-
|
68
|
-
def initialize(options={})
|
69
|
-
@local_root = ::File.expand_path(options[:local_root])
|
70
|
-
|
71
|
-
@endpoint = options[:endpoint] || build_endpoint_from_options(options)
|
72
|
-
end
|
73
|
-
|
74
|
-
def local_root
|
75
|
-
@local_root
|
76
|
-
end
|
77
|
-
|
78
|
-
def path_to(partial)
|
79
|
-
::File.join(@local_root, partial)
|
80
|
-
end
|
81
|
-
|
82
|
-
def copy_object(source_directory_name, source_object_name, target_directory_name, target_object_name, options={})
|
83
|
-
source_path = path_to(::File.join(source_directory_name, source_object_name))
|
84
|
-
target_path = path_to(::File.join(target_directory_name, target_object_name))
|
85
|
-
::FileUtils.mkdir_p(::File.dirname(target_path))
|
86
|
-
::FileUtils.copy_file(source_path, target_path)
|
87
|
-
end
|
88
|
-
|
89
|
-
private
|
90
|
-
def build_endpoint_from_options(options)
|
91
|
-
return unless options[:host]
|
92
|
-
|
93
|
-
URI::Generic.build(options).to_s
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
@@ -1,98 +0,0 @@
|
|
1
|
-
require "fog/schema/data_validator"
|
2
|
-
|
3
|
-
# format related hackery
|
4
|
-
# allows both true.is_a?(Fog::Boolean) and false.is_a?(Fog::Boolean)
|
5
|
-
# allows both nil.is_a?(Fog::Nullable::String) and ''.is_a?(Fog::Nullable::String)
|
6
|
-
module Fog
|
7
|
-
module Boolean; end
|
8
|
-
module Nullable
|
9
|
-
module Boolean; end
|
10
|
-
module Integer; end
|
11
|
-
module String; end
|
12
|
-
module Time; end
|
13
|
-
module Float; end
|
14
|
-
module Hash; end
|
15
|
-
module Array; end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
[FalseClass, TrueClass].each {|klass| klass.send(:include, Fog::Boolean)}
|
19
|
-
[FalseClass, TrueClass, NilClass, Fog::Boolean].each {|klass| klass.send(:include, Fog::Nullable::Boolean)}
|
20
|
-
[NilClass, String].each {|klass| klass.send(:include, Fog::Nullable::String)}
|
21
|
-
[NilClass, Time].each {|klass| klass.send(:include, Fog::Nullable::Time)}
|
22
|
-
[Integer, NilClass].each {|klass| klass.send(:include, Fog::Nullable::Integer)}
|
23
|
-
[Float, NilClass].each {|klass| klass.send(:include, Fog::Nullable::Float)}
|
24
|
-
[Hash, NilClass].each {|klass| klass.send(:include, Fog::Nullable::Hash)}
|
25
|
-
[Array, NilClass].each {|klass| klass.send(:include, Fog::Nullable::Array)}
|
26
|
-
|
27
|
-
module Shindo
|
28
|
-
class Tests
|
29
|
-
# Generates a Shindo test that compares a hash schema to the result
|
30
|
-
# of the passed in block returning true if they match.
|
31
|
-
#
|
32
|
-
# The schema that is passed in is a Hash or Array of hashes that
|
33
|
-
# have Classes in place of values. When checking the schema the
|
34
|
-
# value should match the Class.
|
35
|
-
#
|
36
|
-
# Strict mode will fail if the data has additional keys. Setting
|
37
|
-
# +strict+ to +false+ will allow additional keys to appear.
|
38
|
-
#
|
39
|
-
# @param [Hash] schema A Hash schema
|
40
|
-
# @param [Hash] options Options to change validation rules
|
41
|
-
# @option options [Boolean] :allow_extra_keys
|
42
|
-
# If +true+ does not fail when keys are in the data that are
|
43
|
-
# not specified in the schema. This allows new values to
|
44
|
-
# appear in API output without breaking the check.
|
45
|
-
# @option options [Boolean] :allow_optional_rules
|
46
|
-
# If +true+ does not fail if extra keys are in the schema
|
47
|
-
# that do not match the data. Not recommended!
|
48
|
-
# @yield Data to check with schema
|
49
|
-
#
|
50
|
-
# @example Using in a test
|
51
|
-
# Shindo.tests("comparing welcome data against schema") do
|
52
|
-
# data = {:welcome => "Hello" }
|
53
|
-
# data_matches_schema(:welcome => String) { data }
|
54
|
-
# end
|
55
|
-
#
|
56
|
-
# comparing welcome data against schema
|
57
|
-
# + data matches schema
|
58
|
-
#
|
59
|
-
# @example Example schema
|
60
|
-
# {
|
61
|
-
# "id" => String,
|
62
|
-
# "ram" => Integer,
|
63
|
-
# "disks" => [
|
64
|
-
# {
|
65
|
-
# "size" => Float
|
66
|
-
# }
|
67
|
-
# ],
|
68
|
-
# "dns_name" => Fog::Nullable::String,
|
69
|
-
# "active" => Fog::Boolean,
|
70
|
-
# "created" => DateTime
|
71
|
-
# }
|
72
|
-
#
|
73
|
-
# @return [Boolean]
|
74
|
-
def data_matches_schema(schema, options = {})
|
75
|
-
test('data matches schema') do
|
76
|
-
validator = Fog::Schema::DataValidator.new
|
77
|
-
valid = validator.validate(yield, schema, options)
|
78
|
-
@message = validator.message unless valid
|
79
|
-
valid
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
# @deprecated #formats is deprecated. Use #data_matches_schema instead
|
84
|
-
def formats(format, strict = true)
|
85
|
-
test('has proper format') do
|
86
|
-
if strict
|
87
|
-
options = {:allow_extra_keys => false, :allow_optional_rules => true}
|
88
|
-
else
|
89
|
-
options = {:allow_extra_keys => true, :allow_optional_rules => true}
|
90
|
-
end
|
91
|
-
validator = Fog::Schema::DataValidator.new
|
92
|
-
valid = validator.validate(yield, format, options)
|
93
|
-
@message = validator.message unless valid
|
94
|
-
valid
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
@@ -1,110 +0,0 @@
|
|
1
|
-
Shindo.tests('test_helper', 'meta') do
|
2
|
-
|
3
|
-
tests('comparing welcome data against schema') do
|
4
|
-
data = {:welcome => "Hello" }
|
5
|
-
data_matches_schema(:welcome => String) { data }
|
6
|
-
end
|
7
|
-
|
8
|
-
tests('#data_matches_schema') do
|
9
|
-
tests('when value matches schema expectation') do
|
10
|
-
data_matches_schema({"key" => String}) { {"key" => "Value"} }
|
11
|
-
end
|
12
|
-
|
13
|
-
tests('when values within an array all match schema expectation') do
|
14
|
-
data_matches_schema({"key" => [Integer]}) { {"key" => [1, 2]} }
|
15
|
-
end
|
16
|
-
|
17
|
-
tests('when nested values match schema expectation') do
|
18
|
-
data_matches_schema({"key" => {:nested_key => String}}) { {"key" => {:nested_key => "Value"}} }
|
19
|
-
end
|
20
|
-
|
21
|
-
tests('when collection of values all match schema expectation') do
|
22
|
-
data_matches_schema([{"key" => String}]) { [{"key" => "Value"}, {"key" => "Value"}] }
|
23
|
-
end
|
24
|
-
|
25
|
-
tests('when collection is empty although schema covers optional members') do
|
26
|
-
data_matches_schema([{"key" => String}], {:allow_optional_rules => true}) { [] }
|
27
|
-
end
|
28
|
-
|
29
|
-
tests('when additional keys are passed and not strict') do
|
30
|
-
data_matches_schema({"key" => String}, {:allow_extra_keys => true}) { {"key" => "Value", :extra => "Bonus"} }
|
31
|
-
end
|
32
|
-
|
33
|
-
tests('when value is nil and schema expects NilClass') do
|
34
|
-
data_matches_schema({"key" => NilClass}) { {"key" => nil} }
|
35
|
-
end
|
36
|
-
|
37
|
-
tests('when value and schema match as hashes') do
|
38
|
-
data_matches_schema({}) { {} }
|
39
|
-
end
|
40
|
-
|
41
|
-
tests('when value and schema match as arrays') do
|
42
|
-
data_matches_schema([]) { [] }
|
43
|
-
end
|
44
|
-
|
45
|
-
tests('when value is a Time') do
|
46
|
-
data_matches_schema({"time" => Time}) { {"time" => Time.now} }
|
47
|
-
end
|
48
|
-
|
49
|
-
tests('when key is missing but value should be NilClass (#1477)') do
|
50
|
-
data_matches_schema({"key" => NilClass}, {:allow_optional_rules => true}) { {} }
|
51
|
-
end
|
52
|
-
|
53
|
-
tests('when key is missing but value is nullable (#1477)') do
|
54
|
-
data_matches_schema({"key" => Fog::Nullable::String}, {:allow_optional_rules => true}) { {} }
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
tests('#formats backwards compatible changes') do
|
59
|
-
|
60
|
-
tests('when value matches schema expectation') do
|
61
|
-
formats({"key" => String}) { {"key" => "Value"} }
|
62
|
-
end
|
63
|
-
|
64
|
-
tests('when values within an array all match schema expectation') do
|
65
|
-
formats({"key" => [Integer]}) { {"key" => [1, 2]} }
|
66
|
-
end
|
67
|
-
|
68
|
-
tests('when nested values match schema expectation') do
|
69
|
-
formats({"key" => {:nested_key => String}}) { {"key" => {:nested_key => "Value"}} }
|
70
|
-
end
|
71
|
-
|
72
|
-
tests('when collection of values all match schema expectation') do
|
73
|
-
formats([{"key" => String}]) { [{"key" => "Value"}, {"key" => "Value"}] }
|
74
|
-
end
|
75
|
-
|
76
|
-
tests('when collection is empty although schema covers optional members') do
|
77
|
-
formats([{"key" => String}]) { [] }
|
78
|
-
end
|
79
|
-
|
80
|
-
tests('when additional keys are passed and not strict') do
|
81
|
-
formats({"key" => String}, false) { {"key" => "Value", :extra => "Bonus"} }
|
82
|
-
end
|
83
|
-
|
84
|
-
tests('when value is nil and schema expects NilClass') do
|
85
|
-
formats({"key" => NilClass}) { {"key" => nil} }
|
86
|
-
end
|
87
|
-
|
88
|
-
tests('when value and schema match as hashes') do
|
89
|
-
formats({}) { {} }
|
90
|
-
end
|
91
|
-
|
92
|
-
tests('when value and schema match as arrays') do
|
93
|
-
formats([]) { [] }
|
94
|
-
end
|
95
|
-
|
96
|
-
tests('when value is a Time') do
|
97
|
-
formats({"time" => Time}) { {"time" => Time.now} }
|
98
|
-
end
|
99
|
-
|
100
|
-
tests('when key is missing but value should be NilClass (#1477)') do
|
101
|
-
formats({"key" => NilClass}) { {} }
|
102
|
-
end
|
103
|
-
|
104
|
-
tests('when key is missing but value is nullable (#1477)') do
|
105
|
-
formats({"key" => Fog::Nullable::String}) { {} }
|
106
|
-
end
|
107
|
-
|
108
|
-
end
|
109
|
-
|
110
|
-
end
|
@@ -1,107 +0,0 @@
|
|
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
|