mock_aws_s3_on_memory 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6f82c82dfb3bff2d680c508302a506c79d68aeba
4
+ data.tar.gz: 30350654228691e1641bebfb6f9be071aacc930a
5
+ SHA512:
6
+ metadata.gz: 0b81968a33fe759b402b89eb3a49b9bbffb7cee0a20b531610433bd3014dc9818a667124c7bd21fc166853021b5a310fd1c891a0b5e9adb6d30e47ad163e642b
7
+ data.tar.gz: 061bdfa141c75dec6646650b1098529c85704d80dff941c13e381764c2572a08af7fcd4ca68217601e8030efdf6b969ed87a4efba4bcc67bef98606bf77ecd52
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mock_aws_s3_on_memory.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Yoshiori SHOJI
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,58 @@
1
+ # MockAwsS3OnMemory
2
+ This is a simple gem for mocking out the AWS::S3 library like a [mock-aws-s3](https://github.com/jkrall/mock-aws-s3).
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ gem 'mock_aws_s3_on_memory'
9
+
10
+ And then execute:
11
+
12
+ $ bundle
13
+
14
+ Or install it yourself as:
15
+
16
+ $ gem install mock_aws_s3_on_memory
17
+
18
+ ## Usage
19
+
20
+ ### RSpec
21
+
22
+ Add the following code to `spec/spec_helper`:
23
+
24
+ ```ruby
25
+ require 'mock_aws_s3_on_memory'
26
+
27
+ RSpec.configure do |config|
28
+ config.before(:each) do
29
+ MockAwsS3OnMemory.clear
30
+ end
31
+ end
32
+ ```
33
+
34
+ ```ruby
35
+ [1] pry(main)> require 'mock_aws_s3_on_memory'
36
+ => true
37
+ [2] pry(main)> obj = AWS::S3.new.buckets['my-bucket'].objects['key']
38
+ => <AWS::S3::S3Object:my-bucket/key>
39
+ [3] pry(main)> obj.exists?
40
+ => false
41
+ [4] pry(main)> obj.write("foo")
42
+ => #<StringIO:0x007f98f72eab48>
43
+ [5] pry(main)> obj.exists?
44
+ => true
45
+ [6] pry(main)> obj.delete
46
+ => #<StringIO:0x007f98f72eab48>
47
+ [7] pry(main)> obj.exists?
48
+ => false
49
+ ```
50
+ more example [this library's spec file](spec)
51
+
52
+ ## Contributing
53
+
54
+ 1. Fork it ( https://github.com/[my-github-username]/mock_aws_s3_on_memory/fork )
55
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
56
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
57
+ 4. Push to the branch (`git push origin my-new-feature`)
58
+ 5. Create a new Pull Request
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
@@ -0,0 +1,18 @@
1
+ require 'aws/s3'
2
+
3
+ require "mock_aws_s3_on_memory/version"
4
+ require "mock_aws_s3_on_memory/aws/s3/s3_object"
5
+ require "mock_aws_s3_on_memory/aws/s3/paginated_collection"
6
+ require "mock_aws_s3_on_memory/aws/s3/object_collection"
7
+
8
+ class MockAwsS3OnMemory
9
+ class << self
10
+ def buckets
11
+ @buckets ||= Hash.new {|h, k| h[k] = {} }
12
+ end
13
+
14
+ def clear
15
+ buckets.clear
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ module AWS
2
+ class S3
3
+ class ObjectCollection
4
+ def delete *objects
5
+ objects.flatten.each do |obj|
6
+ obj.delete
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ module AWS
2
+ class S3
3
+ module PaginatedCollection
4
+ protected
5
+ def _each_item markers, limit, options = {}, &block
6
+ options = list_options(options)
7
+ res = AWS::Core::Response.new
8
+ keys = MockAwsS3OnMemory.buckets[bucket.name].keys.select do |key|
9
+ options[:prefix].nil? || key.to_s.start_with?(options[:prefix])
10
+ end
11
+ res.data = {contents: keys.map {|key| {key: key}}, common_prefixes: []}
12
+ each_member_in_page(res, &block)
13
+ nil
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,45 @@
1
+ module AWS
2
+ class S3
3
+ class S3Object
4
+ def initialize(bucket, key, opts = {})
5
+ super
6
+ @key = key
7
+ @bucket = bucket
8
+ end
9
+
10
+ def write_with_put_object options
11
+ buckets[bucket_name][@key] = options[:data]
12
+ end
13
+ alias_method :write_with_multipart, :write_with_put_object
14
+
15
+ def get_object options, &read_block
16
+ data = {data: buckets[bucket_name][@key].read }
17
+ if block_given?
18
+ yield data
19
+ else
20
+ data
21
+ end
22
+ end
23
+
24
+ def copy_from source, options = {}
25
+ buckets[bucket_name][@key] = buckets[bucket_name][source.key]
26
+ end
27
+
28
+ def delete options = {}
29
+ buckets[bucket_name].delete @key
30
+ end
31
+
32
+ def exists?
33
+ buckets[bucket_name].has_key? @key
34
+ end
35
+
36
+ def bucket_name
37
+ bucket.name
38
+ end
39
+
40
+ def buckets
41
+ MockAwsS3OnMemory.buckets
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ class MockAwsS3OnMemory
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mock_aws_s3_on_memory/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mock_aws_s3_on_memory"
8
+ spec.version = MockAwsS3OnMemory::VERSION
9
+ spec.authors = ["Yoshiori SHOJI"]
10
+ spec.email = ["yoshiori@gmail.com"]
11
+ spec.summary = %q{simple AWS::S3 mock. so you can use it in your tests without use the network.}
12
+ spec.description = spec.summary
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "pry-debugger"
25
+ spec.add_development_dependency "webmock"
26
+
27
+ spec.add_dependency "aws-sdk"
28
+ end
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ describe AWS::S3::ObjectCollection do
4
+ let(:s3) do
5
+ AWS::S3.new
6
+ end
7
+
8
+ let(:bucket) do
9
+ s3.buckets['my-bucket']
10
+ end
11
+
12
+ let(:objects) do
13
+ bucket.objects
14
+ end
15
+
16
+ describe "#with_prefix" do
17
+ let(:count) do
18
+ 12
19
+ end
20
+
21
+ context "single prefix" do
22
+ before do
23
+ count.times do |i|
24
+ objects["foo_#{i}"].write("foo")
25
+ end
26
+ objects["bar_1"].write("bar")
27
+ end
28
+
29
+ it "gets values" do
30
+ expect(objects.with_prefix("foo_").count).to be count
31
+ end
32
+ end
33
+
34
+ context "chain prefix" do
35
+ before do
36
+ count.times do |i|
37
+ objects["foo_#{i}"].write("foo")
38
+ end
39
+ objects["bar_1"].write("bar")
40
+ end
41
+
42
+ it "gets values" do
43
+ expect(objects.with_prefix("foo_").with_prefix('1', :append).count).to be 3
44
+ end
45
+ end
46
+ end
47
+
48
+ describe "#delete_all" do
49
+ let(:count) do
50
+ 12
51
+ end
52
+
53
+ before do
54
+ count.times do |i|
55
+ objects["foo_#{i}"].write("foo")
56
+ end
57
+ end
58
+
59
+ it "deletes values" do
60
+ expect {
61
+ objects.delete_all
62
+ }.to change { objects.count }.from(count).to(0)
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ describe AWS::S3::S3Object do
4
+ let(:s3) do
5
+ AWS::S3.new
6
+ end
7
+
8
+ let(:bucket) do
9
+ s3.buckets['my-bucket']
10
+ end
11
+
12
+ let(:obj) do
13
+ bucket.objects['key']
14
+ end
15
+
16
+ describe "#write and #read" do
17
+ it "store value" do
18
+ obj.write("foo")
19
+ expect(obj.read).to eq "foo"
20
+ end
21
+ end
22
+
23
+ describe "#exists?" do
24
+ context "exist value" do
25
+ before do
26
+ obj.write("foo")
27
+ end
28
+
29
+ it { expect(obj).to be_exist}
30
+ end
31
+
32
+ context "not exist value" do
33
+ it { expect(obj).to_not be_exist }
34
+ end
35
+ end
36
+
37
+ describe "#delete" do
38
+ before do
39
+ obj.write("foo")
40
+ end
41
+
42
+ it "delete value" do
43
+ expect {
44
+ obj.delete
45
+ }.to change { obj.exists? }.from(true).to(false)
46
+ end
47
+ end
48
+
49
+ describe "#copy_from" do
50
+ before do
51
+ obj.write("foo")
52
+ end
53
+
54
+ it "copy value" do
55
+ expect {
56
+ bucket.objects["bar"].copy_from(obj)
57
+ }.to change { bucket.objects["bar"].exists? }.from(false).to(true)
58
+ end
59
+ end
60
+
61
+ describe "#copy_to" do
62
+ before do
63
+ obj.write("foo")
64
+ end
65
+
66
+ it "copy value" do
67
+ expect {
68
+ obj.copy_to("bar")
69
+ }.to change { bucket.objects["bar"].exists? }.from(false).to(true)
70
+ end
71
+ end
72
+
73
+ describe "#move_to" do
74
+ before do
75
+ obj.write("foo")
76
+ end
77
+
78
+ it "move value" do
79
+ expect {
80
+ obj.move_to("bar")
81
+ }.to change { bucket.objects["bar"].exists? }.from(false).to(true)
82
+ expect(obj).to_not be_exist
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe MockAwsS3OnMemory do
4
+ it 'has a version number' do
5
+ expect(MockAwsS3OnMemory::VERSION).not_to be nil
6
+ end
7
+
8
+ describe ".buckets" do
9
+ it 'returns hash' do
10
+ expect(MockAwsS3OnMemory.buckets).to be_a Hash
11
+ end
12
+
13
+ it 'returns same instance' do
14
+ expect(MockAwsS3OnMemory.buckets).to be MockAwsS3OnMemory.buckets
15
+ end
16
+ end
17
+
18
+ describe ".clear" do
19
+ before do
20
+ MockAwsS3OnMemory.buckets[:hoge] = :foo
21
+ end
22
+
23
+ it 'empty buckets' do
24
+ expect {
25
+ MockAwsS3OnMemory.clear
26
+ }.to change { MockAwsS3OnMemory.buckets.size }.from(1).to(0)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ require 'mock_aws_s3_on_memory'
4
+
5
+ # check do not use http request
6
+ require 'webmock/rspec'
7
+
8
+ RSpec.configure do |config|
9
+ config.before(:each) do
10
+ MockAwsS3OnMemory.clear
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mock_aws_s3_on_memory
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yoshiori SHOJI
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-debugger
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: aws-sdk
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: simple AWS::S3 mock. so you can use it in your tests without use the
98
+ network.
99
+ email:
100
+ - yoshiori@gmail.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - lib/mock_aws_s3_on_memory.rb
113
+ - lib/mock_aws_s3_on_memory/aws/s3/object_collection.rb
114
+ - lib/mock_aws_s3_on_memory/aws/s3/paginated_collection.rb
115
+ - lib/mock_aws_s3_on_memory/aws/s3/s3_object.rb
116
+ - lib/mock_aws_s3_on_memory/version.rb
117
+ - mock_aws_s3_on_memory.gemspec
118
+ - spec/lib/mock_aws_s3_on_memory/aws/s3/object_collection_spec.rb
119
+ - spec/lib/mock_aws_s3_on_memory/aws/s3/s3_object_spec.rb
120
+ - spec/lib/mock_aws_s3_on_memory_spec.rb
121
+ - spec/spec_helper.rb
122
+ homepage: ''
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.2.2
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: simple AWS::S3 mock. so you can use it in your tests without use the network.
146
+ test_files:
147
+ - spec/lib/mock_aws_s3_on_memory/aws/s3/object_collection_spec.rb
148
+ - spec/lib/mock_aws_s3_on_memory/aws/s3/s3_object_spec.rb
149
+ - spec/lib/mock_aws_s3_on_memory_spec.rb
150
+ - spec/spec_helper.rb