fake_dynamo 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -20,6 +20,12 @@ gem install fake_dynamo
20
20
  fake_dynamo --port 4567
21
21
  ````
22
22
 
23
+ send a DELETE request to reset the database. eg
24
+
25
+ ````
26
+ curl -X DELETE http://localhost:4567
27
+ ````
28
+
23
29
  # Clients
24
30
 
25
31
  * aws-sdk
data/bin/fake_dynamo CHANGED
@@ -19,8 +19,35 @@ OptionParser.new do |opts|
19
19
  opts.on("-c", "--compact", "Default: #{options[:compact]}") do |v|
20
20
  options[:compact] = v
21
21
  end
22
+
23
+ opts.on "-P", "--pid PIDFILE", "Where to write the pid" do |pid|
24
+ options[:pid] = pid
25
+ end
26
+
27
+ opts.on "-d", "--[no-]daemonize", "Detaches the process" do |daemonize|
28
+ options[:daemonize] = daemonize
29
+ end
30
+
22
31
  end.parse!
23
32
 
33
+ if options[:daemonize]
34
+ Process.daemon(true, true)
35
+ end
36
+
37
+ if (pid = options[:pid])
38
+ if File.exist?(pid)
39
+ existing_pid = File.open(pid, 'r').read.chomp.to_i
40
+ running = Process.getpgid(existing_pid) rescue false
41
+ if running
42
+ warn "Error, Process #{existing_pid} already running"
43
+ exit 1
44
+ else
45
+ warn "Cleaning up stale pid at #{pid}"
46
+ end
47
+ end
48
+ File.open(pid, 'w') { |f| f.write(Process.pid) }
49
+ end
50
+
24
51
  FakeDynamo::Storage.db_path = options[:db]
25
52
 
26
53
  if options[:compact]
@@ -5,7 +5,7 @@ module FakeDynamo
5
5
  def initialize(name, value, type)
6
6
  @name, @value, @type = name, value, type
7
7
 
8
- if @type == 'B'
8
+ if @type == 'B' and value
9
9
  @value = Base64.decode64(value)
10
10
  end
11
11
 
@@ -15,6 +15,10 @@ module FakeDynamo
15
15
  @tables = {}
16
16
  end
17
17
 
18
+ def reset
19
+ @tables = {}
20
+ end
21
+
18
22
  def process(operation, data)
19
23
  validate_payload(operation, data)
20
24
  operation = operation.underscore
@@ -26,6 +26,12 @@ module FakeDynamo
26
26
  [status, response.to_json]
27
27
  end
28
28
 
29
+ delete '/' do
30
+ db.reset
31
+ storage.reset
32
+ {success: true}.to_json
33
+ end
34
+
29
35
  def db
30
36
  DB.instance
31
37
  end
@@ -41,6 +41,13 @@ module FakeDynamo
41
41
  FileUtils.rm(db_path)
42
42
  end
43
43
 
44
+ def reset
45
+ puts "resetting database ..."
46
+ @aof.close if @aof
47
+ @aof = nil
48
+ delete_db
49
+ end
50
+
44
51
  def db
45
52
  DB.instance
46
53
  end
@@ -1,3 +1,3 @@
1
1
  module FakeDynamo
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -34,5 +34,20 @@ module FakeDynamo
34
34
  last_response.status.should eq(400)
35
35
  end
36
36
 
37
+ it "should reset database" do
38
+ post '/', {}.to_json, 'HTTP_X_AMZ_TARGET' => 'DynamoDB_20111205.ListTables'
39
+ JSON.parse(last_response.body)["TableNames"].size.should == 1
40
+
41
+ delete '/'
42
+ last_response.should be_ok
43
+
44
+ post '/', {}.to_json, 'HTTP_X_AMZ_TARGET' => 'DynamoDB_20111205.ListTables'
45
+ JSON.parse(last_response.body)["TableNames"].size.should == 0
46
+
47
+ post '/', data.to_json, 'HTTP_X_AMZ_TARGET' => 'DynamoDB_20111205.CreateTable'
48
+ post '/', {}.to_json, 'HTTP_X_AMZ_TARGET' => 'DynamoDB_20111205.ListTables'
49
+ JSON.parse(last_response.body)["TableNames"].size.should == 1
50
+ end
51
+
37
52
  end
38
53
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fake_dynamo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-11 00:00:00.000000000Z
12
+ date: 2013-03-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
16
- requirement: &70342224155740 !ruby/object:Gem::Requirement
16
+ requirement: &70338580048120 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70342224155740
24
+ version_requirements: *70338580048120
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activesupport
27
- requirement: &70342224155280 !ruby/object:Gem::Requirement
27
+ requirement: &70338580047540 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70342224155280
35
+ version_requirements: *70338580047540
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: json
38
- requirement: &70342224154860 !ruby/object:Gem::Requirement
38
+ requirement: &70338580046980 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70342224154860
46
+ version_requirements: *70338580046980
47
47
  description:
48
48
  email:
49
49
  - ananthakumaran@gmail.com