optimus_prime 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/optimus_prime.rb +4 -0
- data/lib/optimus_prime/server.rb +17 -6
- data/lib/optimus_prime/version.rb +1 -1
- data/optimus_prime.log +49 -0
- data/spec/lib/optimus_prime_spec.rb +16 -31
- data/spec/lib/start_stop_spec.rb +19 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79382a0cd439f8c3e2fe3e39036c3733de719e53
|
4
|
+
data.tar.gz: b476f6bd79cdbc27eb13beb59fd61262830ca617
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 225dd5cd8d2e15f6f11127e74c4e091e69a467000ab6032518dd37fcc48c1b53c0aa807e0eda7eb490c4963f1911375e69c28f024cb1e7d34b9175a9666a6c4d
|
7
|
+
data.tar.gz: 1a96b86edca6c5d89e6ddc614f0488ee60b18f6baf85913c21f857d342e42fdf27952b040fa70bce12521a418feee5d9dc85286302962f0d4d6b2d62dc54b6ed
|
data/README.md
CHANGED
@@ -67,7 +67,7 @@ response.status #=> 404
|
|
67
67
|
|
68
68
|
## Assert on a POST request body
|
69
69
|
```ruby
|
70
|
-
op.prime("users", " response... ",
|
70
|
+
op.prime("users", " response... ", requested_with: "a body")
|
71
71
|
response = Faraday.post("http://localhost:7002/get/users", "I am a body")
|
72
72
|
response.status #=> 200
|
73
73
|
```
|
data/lib/optimus_prime.rb
CHANGED
data/lib/optimus_prime/server.rb
CHANGED
@@ -12,20 +12,27 @@ module OptimusPrime
|
|
12
12
|
path = self.env["REQUEST_URI"].sub("/get/", "")
|
13
13
|
response = responses[path]
|
14
14
|
return 404 if response.nil?
|
15
|
-
sleep(response[:sleep].to_f) if response[:sleep]
|
16
15
|
|
17
|
-
if response[:
|
18
|
-
return 404 unless eval("request.body.string.include?('#{response[:
|
16
|
+
if response[:requested_with]
|
17
|
+
return 404 unless eval("request.body.string.include?('#{response[:requested_with]}')")
|
19
18
|
end
|
20
19
|
|
21
20
|
content_type(response[:content_type])
|
22
21
|
status(response[:status_code])
|
22
|
+
|
23
|
+
sleep(response[:sleep].to_i) if response[:sleep]
|
24
|
+
|
23
25
|
response[:body]
|
24
26
|
end
|
25
27
|
|
26
|
-
|
28
|
+
def get_response
|
27
29
|
path = self.env["REQUEST_URI"].sub("/get/", "")
|
28
|
-
|
30
|
+
responses[path]
|
31
|
+
end
|
32
|
+
|
33
|
+
get "/get/*" do
|
34
|
+
#path = self.env["REQUEST_URI"].sub("/get/", "")
|
35
|
+
response = get_response
|
29
36
|
return 404 if response.nil?
|
30
37
|
sleep(response[:sleep].to_f) if response[:sleep]
|
31
38
|
|
@@ -36,7 +43,7 @@ module OptimusPrime
|
|
36
43
|
|
37
44
|
post "/prime" do
|
38
45
|
path = params["path_name"]
|
39
|
-
responses[path] = { content_type: (params["content_type"] || :html), body: params["response"], status_code: (params["status_code"] || 200),
|
46
|
+
responses[path] = { content_type: (params["content_type"] || :html), body: params["response"], status_code: (params["status_code"] || 200), requested_with: (params["requested_with"] || false), sleep: (params["sleep"] || false) }
|
40
47
|
201
|
41
48
|
end
|
42
49
|
|
@@ -45,6 +52,10 @@ module OptimusPrime
|
|
45
52
|
responses.to_json
|
46
53
|
end
|
47
54
|
|
55
|
+
get "/clear" do
|
56
|
+
@@responses = {}
|
57
|
+
end
|
58
|
+
|
48
59
|
private
|
49
60
|
|
50
61
|
def responses
|
data/optimus_prime.log
CHANGED
@@ -1502,3 +1502,52 @@ Thin web server (v1.6.2 codename Doc Brown)
|
|
1502
1502
|
Debugging ON
|
1503
1503
|
Maximum connections set to 1024
|
1504
1504
|
Listening on 0.0.0.0:7002, CTRL+C to stop
|
1505
|
+
Writing PID to /Users/acnalesso/dev/optimus_prime/tmp/pids/optimus_prime.pid
|
1506
|
+
Using rack adapter
|
1507
|
+
Thin web server (v1.6.2 codename Doc Brown)
|
1508
|
+
Debugging ON
|
1509
|
+
Maximum connections set to 1024
|
1510
|
+
Listening on 0.0.0.0:7002, CTRL+C to stop
|
1511
|
+
Exiting!
|
1512
|
+
Writing PID to /Users/acnalesso/dev/optimus_prime/tmp/pids/optimus_prime.pid
|
1513
|
+
Using rack adapter
|
1514
|
+
Thin web server (v1.6.2 codename Doc Brown)
|
1515
|
+
Debugging ON
|
1516
|
+
Maximum connections set to 1024
|
1517
|
+
Listening on 0.0.0.0:7002, CTRL+C to stop
|
1518
|
+
Exiting!
|
1519
|
+
Writing PID to /Users/acnalesso/dev/optimus_prime/tmp/pids/optimus_prime.pid
|
1520
|
+
Using rack adapter
|
1521
|
+
Thin web server (v1.6.2 codename Doc Brown)
|
1522
|
+
Debugging ON
|
1523
|
+
Maximum connections set to 1024
|
1524
|
+
Listening on 0.0.0.0:7002, CTRL+C to stop
|
1525
|
+
Exiting!
|
1526
|
+
Writing PID to /Users/acnalesso/dev/optimus_prime/tmp/pids/optimus_prime.pid
|
1527
|
+
Using rack adapter
|
1528
|
+
Thin web server (v1.6.2 codename Doc Brown)
|
1529
|
+
Debugging ON
|
1530
|
+
Maximum connections set to 1024
|
1531
|
+
Listening on 0.0.0.0:7002, CTRL+C to stop
|
1532
|
+
Waiting for 1 connection(s) to finish, can take up to 30 sec, CTRL+C to stop now
|
1533
|
+
Exiting!
|
1534
|
+
Writing PID to /Users/acnalesso/dev/optimus_prime/tmp/pids/optimus_prime.pid
|
1535
|
+
Using rack adapter
|
1536
|
+
Thin web server (v1.6.2 codename Doc Brown)
|
1537
|
+
Debugging ON
|
1538
|
+
Maximum connections set to 1024
|
1539
|
+
Listening on 0.0.0.0:7002, CTRL+C to stop
|
1540
|
+
Exiting!
|
1541
|
+
Writing PID to /Users/acnalesso/dev/optimus_prime/tmp/pids/optimus_prime.pid
|
1542
|
+
Using rack adapter
|
1543
|
+
Thin web server (v1.6.2 codename Doc Brown)
|
1544
|
+
Debugging ON
|
1545
|
+
Maximum connections set to 1024
|
1546
|
+
Listening on 0.0.0.0:7002, CTRL+C to stop
|
1547
|
+
Exiting!
|
1548
|
+
Writing PID to /Users/acnalesso/dev/optimus_prime/tmp/pids/optimus_prime.pid
|
1549
|
+
Using rack adapter
|
1550
|
+
Thin web server (v1.6.2 codename Doc Brown)
|
1551
|
+
Debugging ON
|
1552
|
+
Maximum connections set to 1024
|
1553
|
+
Listening on 0.0.0.0:7002, CTRL+C to stop
|
@@ -69,30 +69,10 @@ describe OptimusPrime do
|
|
69
69
|
expect( JSON.parse(response.body) ).to eq({ "username" => "Test" })
|
70
70
|
end
|
71
71
|
|
72
|
-
context "Starting and Stopping the server" do
|
73
|
-
it "starts the server" do
|
74
|
-
OptimusPrime.restart_server
|
75
|
-
expect( `ls ./tmp/pids` ).to include("optimus_prime.pid")
|
76
|
-
end
|
77
|
-
|
78
|
-
it "stops the server" do
|
79
|
-
OptimusPrime.start_server
|
80
|
-
OptimusPrime.stop_server
|
81
|
-
expect( `ls ./tmp/pids` ).to_not include("optimus_prime.pid")
|
82
|
-
OptimusPrime.start_server
|
83
|
-
end
|
84
|
-
|
85
|
-
it "informs me if the server is already running" do
|
86
|
-
OptimusPrime.start_server
|
87
|
-
expect( OptimusPrime.start_server ).to include("Optimus is already priming :)")
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
72
|
context "Asserting on request content" do
|
93
73
|
|
94
74
|
it "returns a 404 if the request body does not match the assertion" do
|
95
|
-
op.prime("user", { username: "Test" }.to_json, content_type: :json,
|
75
|
+
op.prime("user", { username: "Test" }.to_json, content_type: :json, requested_with: "haha")
|
96
76
|
|
97
77
|
response = ::Faraday.post('http://localhost:7002/get/user', "I am a body")
|
98
78
|
|
@@ -100,7 +80,7 @@ describe OptimusPrime do
|
|
100
80
|
end
|
101
81
|
|
102
82
|
it "returns a 200 if the request body does match the assertion" do
|
103
|
-
op.prime("user", { username: "Test" }.to_json, content_type: :json,
|
83
|
+
op.prime("user", { username: "Test" }.to_json, content_type: :json, requested_with: "I am a body")
|
104
84
|
|
105
85
|
response = ::Faraday.post('http://localhost:7002/get/user', "I am a body")
|
106
86
|
|
@@ -110,24 +90,29 @@ describe OptimusPrime do
|
|
110
90
|
end
|
111
91
|
|
112
92
|
context "Server processing" do
|
113
|
-
it "#GET tells the server to sleep for n seconds in order to reproduce timeouts" do
|
114
|
-
op.prime("user", { username: "Test" }.to_json, content_type: :json, sleep: 10)
|
115
93
|
|
94
|
+
it "#GET tells the server to sleep for 10 seconds in order to reproduce timeouts" do
|
95
|
+
op.prime("userAsleep", { username: "Test" }.to_json, content_type: :json, sleep: 10)
|
96
|
+
|
97
|
+
f = ::Faraday.new('http://localhost:7002/get/')
|
98
|
+
f.options.timeout = 0
|
116
99
|
|
117
|
-
|
118
|
-
::Faraday.get('http://localhost:7002/get/user') { |r| r.options.timeout = 0.2 }
|
119
|
-
end.to raise_error
|
100
|
+
expect { f.get("/userAsleep") }.to raise_error(Faraday::TimeoutError)
|
120
101
|
|
102
|
+
op.clear!
|
121
103
|
end
|
122
104
|
|
123
105
|
it "#POST tells the server to sleep for n seconds in order to reproduce timeouts" do
|
124
|
-
op.prime("
|
106
|
+
op.prime("userAsleepAgain", { username: "Test" }.to_json, content_type: :json, sleep: 10)
|
125
107
|
|
126
|
-
|
127
|
-
|
128
|
-
end.to raise_error
|
108
|
+
f = ::Faraday.new('http://localhost:7002/get/')
|
109
|
+
f.options.timeout = 0
|
129
110
|
|
111
|
+
expect { f.get("/userAsleepAgain") }.to raise_error(Faraday::TimeoutError)
|
112
|
+
|
113
|
+
op.clear!
|
130
114
|
end
|
115
|
+
|
131
116
|
end
|
132
117
|
|
133
118
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
describe OptimusPrime, "Starting and Stopping the server" do
|
2
|
+
it "starts the server" do
|
3
|
+
OptimusPrime.restart_server
|
4
|
+
expect( `ls ./tmp/pids` ).to include("optimus_prime.pid")
|
5
|
+
end
|
6
|
+
|
7
|
+
it "stops the server" do
|
8
|
+
OptimusPrime.start_server
|
9
|
+
OptimusPrime.stop_server
|
10
|
+
expect( `ls ./tmp/pids` ).to_not include("optimus_prime.pid")
|
11
|
+
OptimusPrime.start_server
|
12
|
+
end
|
13
|
+
|
14
|
+
it "informs me if the server is already running" do
|
15
|
+
OptimusPrime.start_server
|
16
|
+
expect( OptimusPrime.start_server ).to include("Optimus is already priming :)")
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: optimus_prime
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Antonio Nalesso
|
@@ -101,6 +101,7 @@ files:
|
|
101
101
|
- optimus_prime.gemspec
|
102
102
|
- optimus_prime.log
|
103
103
|
- spec/lib/optimus_prime_spec.rb
|
104
|
+
- spec/lib/start_stop_spec.rb
|
104
105
|
- spec/spec_helper.rb
|
105
106
|
homepage: ''
|
106
107
|
licenses:
|
@@ -128,4 +129,5 @@ specification_version: 4
|
|
128
129
|
summary: Create endpoints and persists data
|
129
130
|
test_files:
|
130
131
|
- spec/lib/optimus_prime_spec.rb
|
132
|
+
- spec/lib/start_stop_spec.rb
|
131
133
|
- spec/spec_helper.rb
|