fake_dynamo 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/Gemfile +11 -0
- data/Guardfile +19 -0
- data/LICENSE +22 -0
- data/README.md +4 -0
- data/Rakefile +2 -0
- data/bin/fake_dynamo +17 -0
- data/fake_dynamo.gemspec +18 -0
- data/lib/fake_dynamo.rb +20 -0
- data/lib/fake_dynamo/api.yml +734 -0
- data/lib/fake_dynamo/attribute.rb +54 -0
- data/lib/fake_dynamo/db.rb +113 -0
- data/lib/fake_dynamo/exceptions.rb +57 -0
- data/lib/fake_dynamo/filter.rb +110 -0
- data/lib/fake_dynamo/item.rb +102 -0
- data/lib/fake_dynamo/key.rb +71 -0
- data/lib/fake_dynamo/key_schema.rb +26 -0
- data/lib/fake_dynamo/server.rb +43 -0
- data/lib/fake_dynamo/storage.rb +71 -0
- data/lib/fake_dynamo/table.rb +362 -0
- data/lib/fake_dynamo/validation.rb +155 -0
- data/lib/fake_dynamo/version.rb +3 -0
- data/spec/fake_dynamo/db_spec.rb +257 -0
- data/spec/fake_dynamo/filter_spec.rb +122 -0
- data/spec/fake_dynamo/item_spec.rb +97 -0
- data/spec/fake_dynamo/server_spec.rb +47 -0
- data/spec/fake_dynamo/table_spec.rb +435 -0
- data/spec/fake_dynamo/validation_spec.rb +63 -0
- data/spec/spec_helper.rb +28 -0
- metadata +105 -0
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module FakeDynamo
|
4
|
+
class ValidationTest
|
5
|
+
include Validation
|
6
|
+
end
|
7
|
+
|
8
|
+
describe Validation do
|
9
|
+
let(:data) do
|
10
|
+
{
|
11
|
+
"TableName" => "Table1",
|
12
|
+
"KeySchema" =>
|
13
|
+
{"HashKeyElement" => {"AttributeName" => "AttributeName1","AttributeType" => "S"},
|
14
|
+
"RangeKeyElement" => {"AttributeName" => "AttributeName2","AttributeType" => "N"}},
|
15
|
+
"ProvisionedThroughput" => {"ReadCapacityUnits" => 5,"WriteCapacityUnits" => 10}
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
subject { ValidationTest.new }
|
20
|
+
|
21
|
+
it 'should validate table name' do
|
22
|
+
{ '&**' => /pattern/,
|
23
|
+
'x' => /within/,
|
24
|
+
'x' * 500 => /within/,
|
25
|
+
}.each do |name, msg|
|
26
|
+
data['TableName'] = name
|
27
|
+
expect { subject.validate_payload('CreateTable', data) }.to raise_error(ValidationException, msg)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
%w[ReadCapacityUnits WriteCapacityUnits].each do |units|
|
32
|
+
it "should validate numericality of #{units}" do
|
33
|
+
data['ProvisionedThroughput']['ReadCapacityUnits'] = 'xxx'
|
34
|
+
expect { subject.validate_payload('CreateTable', data) }.to raise_error(ValidationException, /long/)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
context '#validate_key_data' do
|
40
|
+
let(:schema) do
|
41
|
+
KeySchema.new({'HashKeyElement' => { 'AttributeName' => 'id', 'AttributeType' => 'S'}})
|
42
|
+
end
|
43
|
+
|
44
|
+
let(:schema_with_range) do
|
45
|
+
KeySchema.new({'HashKeyElement' => { 'AttributeName' => 'id', 'AttributeType' => 'S'},
|
46
|
+
'RangeKeyElement' => { 'AttributeName' => 'time', 'AttributeType' => 'N'}})
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should validate the schema' do
|
50
|
+
[[{'HashKeyElement' => { 'N' => '1234' }}, schema, /mismatch/],
|
51
|
+
[{'HashKeyElement' => { 'S' => '1234' }}, schema_with_range, /missing.*range/i],
|
52
|
+
[{'HashKeyElement' => { 'S' => '1234' }, 'RangeKeyElement' => { 'N' => '1234'}}, schema, /not present/],
|
53
|
+
[{'HashKeyElement' => { 'S' => '1234' }, 'RangeKeyElement' => { 'S' => '1234'}}, schema_with_range, /mismatch/]
|
54
|
+
].each do |data, schema, message|
|
55
|
+
expect do
|
56
|
+
subject.validate_key_data(data, schema)
|
57
|
+
end.to raise_error(ValidationException, message)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
$: << File.join(File.dirname(File.dirname(__FILE__)), "lib")
|
2
|
+
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start
|
5
|
+
|
6
|
+
require 'rspec'
|
7
|
+
require 'rack/test'
|
8
|
+
require 'fake_dynamo'
|
9
|
+
require 'pry'
|
10
|
+
|
11
|
+
module Utils
|
12
|
+
def self.deep_copy(x)
|
13
|
+
Marshal.load(Marshal.dump(x))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
module FakeDynamo
|
18
|
+
class Storage
|
19
|
+
def initialize
|
20
|
+
delete_db
|
21
|
+
super
|
22
|
+
end
|
23
|
+
|
24
|
+
def db_path
|
25
|
+
'/usr/local/var/fake_dynamo/test_db.fdb'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fake_dynamo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Anantha Kumaran
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sinatra
|
16
|
+
requirement: &70353447666560 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70353447666560
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: activesupport
|
27
|
+
requirement: &70353447665600 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70353447665600
|
36
|
+
description:
|
37
|
+
email:
|
38
|
+
- ananthakumaran@gmail.com
|
39
|
+
executables:
|
40
|
+
- fake_dynamo
|
41
|
+
extensions: []
|
42
|
+
extra_rdoc_files: []
|
43
|
+
files:
|
44
|
+
- .gitignore
|
45
|
+
- .rspec
|
46
|
+
- Gemfile
|
47
|
+
- Guardfile
|
48
|
+
- LICENSE
|
49
|
+
- README.md
|
50
|
+
- Rakefile
|
51
|
+
- bin/fake_dynamo
|
52
|
+
- fake_dynamo.gemspec
|
53
|
+
- lib/fake_dynamo.rb
|
54
|
+
- lib/fake_dynamo/api.yml
|
55
|
+
- lib/fake_dynamo/attribute.rb
|
56
|
+
- lib/fake_dynamo/db.rb
|
57
|
+
- lib/fake_dynamo/exceptions.rb
|
58
|
+
- lib/fake_dynamo/filter.rb
|
59
|
+
- lib/fake_dynamo/item.rb
|
60
|
+
- lib/fake_dynamo/key.rb
|
61
|
+
- lib/fake_dynamo/key_schema.rb
|
62
|
+
- lib/fake_dynamo/server.rb
|
63
|
+
- lib/fake_dynamo/storage.rb
|
64
|
+
- lib/fake_dynamo/table.rb
|
65
|
+
- lib/fake_dynamo/validation.rb
|
66
|
+
- lib/fake_dynamo/version.rb
|
67
|
+
- spec/fake_dynamo/db_spec.rb
|
68
|
+
- spec/fake_dynamo/filter_spec.rb
|
69
|
+
- spec/fake_dynamo/item_spec.rb
|
70
|
+
- spec/fake_dynamo/server_spec.rb
|
71
|
+
- spec/fake_dynamo/table_spec.rb
|
72
|
+
- spec/fake_dynamo/validation_spec.rb
|
73
|
+
- spec/spec_helper.rb
|
74
|
+
homepage:
|
75
|
+
licenses: []
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 1.8.15
|
95
|
+
signing_key:
|
96
|
+
specification_version: 3
|
97
|
+
summary: local hosted, inmemory fake dynamodb
|
98
|
+
test_files:
|
99
|
+
- spec/fake_dynamo/db_spec.rb
|
100
|
+
- spec/fake_dynamo/filter_spec.rb
|
101
|
+
- spec/fake_dynamo/item_spec.rb
|
102
|
+
- spec/fake_dynamo/server_spec.rb
|
103
|
+
- spec/fake_dynamo/table_spec.rb
|
104
|
+
- spec/fake_dynamo/validation_spec.rb
|
105
|
+
- spec/spec_helper.rb
|