This repository was archived by the owner on Mar 30, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +49
-10
lines changed Expand file tree Collapse file tree 4 files changed +49
-10
lines changed Original file line number Diff line number Diff line change 1
- test : linter compose-up-test test_deps
1
+ test : compose-up-test test_deps
2
2
sleep 5
3
3
bundle exec rspec ./tests/spec
4
4
docker-compose -f docker-compose-test.yml down
Original file line number Diff line number Diff line change 1
1
API GATEWAY DEMO
2
2
================
3
3
4
- Simple nginx gateway with tests.
4
+ This is an example how to test nginx api gateway with ruby rspec.
5
+
6
+ # Prerequisites
7
+ * [ docker] ( https://www.docker.com/ )
8
+ * [ docker-compose] ( https://docs.docker.com/compose/ )
9
+ * [ ruby 2.4.0] ( https://www.ruby-lang.org/en/news/2016/12/25/ruby-2-4-0-released/ )
10
+ * [ bundler] ( http://bundler.io/ )
11
+
12
+ # Run tests
13
+ Set up testing environment:
14
+ ~~~ bash
15
+ $ make compose-up-test
16
+ ~~~
17
+
18
+ Execute tests:
19
+ ~~~ bash
20
+ $ make test
21
+ ~~~
Original file line number Diff line number Diff line change @@ -4,12 +4,10 @@ worker_processes 1;
4
4
error_log /var/log/nginx/error.log warn ;
5
5
pid /var/run/nginx.pid;
6
6
7
-
8
7
events {
9
8
worker_connections 1024 ;
10
9
}
11
10
12
-
13
11
http {
14
12
include /etc/nginx/mime.types;
15
13
default_type application/octet-stream;
@@ -23,11 +21,6 @@ http {
23
21
access_log /var/log/nginx/access.log main ;
24
22
25
23
sendfile on ;
26
- #tcp_nopush on;
27
-
28
24
keepalive_timeout 65 ;
29
-
30
- #gzip on;
31
-
32
25
include /etc/nginx/conf.d/*.conf;
33
26
}
Original file line number Diff line number Diff line change 1
1
describe "gateway" do
2
- context "_health" do
2
+ context "/ _health" do
3
3
context "get" do
4
4
result = Client . get "http://localhost:81/_health"
5
5
it "return 200" do
19
19
it "proxy to service2" do
20
20
expect ( result . body ) . to eq ( "https://service2.myapi.com/v1/path1" )
21
21
end
22
+ it "response header does not contain nginx version" do
23
+ expect ( result . headers [ :server ] ) . to eq ( "nginx" )
24
+ end
22
25
end
23
26
context "/some_id" do
24
27
context "get" do
29
32
it "proxy to service1" do
30
33
expect ( result . body ) . to eq ( "https://service1.myapi.com/v1/path1/some_id" )
31
34
end
35
+ it "response header does not contain nginx version" do
36
+ expect ( result . headers [ :server ] ) . to eq ( "nginx" )
37
+ end
38
+ end
39
+ end
40
+ end
41
+ context "/path2" do
42
+ context "get" do
43
+ result = Client . get "http://localhost:81/path2"
44
+ it "return 404" do
45
+ expect ( result . code ) . to eq ( 404 )
46
+ end
47
+ it "response header does not contain nginx version" do
48
+ expect ( result . headers [ :server ] ) . to eq ( "nginx" )
49
+ end
50
+ end
51
+ context "/some_id" do
52
+ result = Client . get "http://localhost:81/path2/some_id"
53
+ it "return 200" do
54
+ expect ( result . code ) . to eq ( 200 )
55
+ end
56
+ it "proxy to service3" do
57
+ expect ( result . body ) . to eq ( "https://service3.myapi.com/v1/path2/some_id" )
58
+ end
59
+ it "response header does not contain nginx version" do
60
+ expect ( result . headers [ :server ] ) . to eq ( "nginx" )
32
61
end
33
62
end
34
63
end
You can’t perform that action at this time.
0 commit comments