Skip to content
This repository was archived by the owner on Mar 30, 2024. It is now read-only.

Commit a23bf55

Browse files
MateuszMateusz
authored andcommitted
Add more sample tests + cleanup
1 parent 006e908 commit a23bf55

File tree

4 files changed

+49
-10
lines changed

4 files changed

+49
-10
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
test: linter compose-up-test test_deps
1+
test: compose-up-test test_deps
22
sleep 5
33
bundle exec rspec ./tests/spec
44
docker-compose -f docker-compose-test.yml down

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
11
API GATEWAY DEMO
22
================
33

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+
~~~

nginx/nginx.conf

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ worker_processes 1;
44
error_log /var/log/nginx/error.log warn;
55
pid /var/run/nginx.pid;
66

7-
87
events {
98
worker_connections 1024;
109
}
1110

12-
1311
http {
1412
include /etc/nginx/mime.types;
1513
default_type application/octet-stream;
@@ -23,11 +21,6 @@ http {
2321
access_log /var/log/nginx/access.log main;
2422

2523
sendfile on;
26-
#tcp_nopush on;
27-
2824
keepalive_timeout 65;
29-
30-
#gzip on;
31-
3225
include /etc/nginx/conf.d/*.conf;
3326
}

tests/spec/gateway_spec.rb

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
describe "gateway" do
2-
context "_health" do
2+
context "/_health" do
33
context "get" do
44
result = Client.get "http://localhost:81/_health"
55
it "return 200" do
@@ -19,6 +19,9 @@
1919
it "proxy to service2" do
2020
expect(result.body).to eq("https://service2.myapi.com/v1/path1")
2121
end
22+
it "response header does not contain nginx version" do
23+
expect(result.headers[:server]).to eq("nginx")
24+
end
2225
end
2326
context "/some_id" do
2427
context "get" do
@@ -29,6 +32,32 @@
2932
it "proxy to service1" do
3033
expect(result.body).to eq("https://service1.myapi.com/v1/path1/some_id")
3134
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")
3261
end
3362
end
3463
end

0 commit comments

Comments
 (0)