-
-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Use ruby rspec to run unit tests (#347)
* Use ruby rspec to run unit tests
- Loading branch information
Showing
22 changed files
with
320 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,5 @@ contrib/kubernetes/helm/alerta/charts | |
.env.*.local | ||
|
||
.idea/* | ||
|
||
/.bundle/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,8 @@ http { | |
|
||
include /etc/nginx/mime.types; | ||
|
||
server_tokens off; | ||
|
||
gzip on; | ||
gzip_disable "msie6"; | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--color | ||
--require ./spec/helpers/spec_helper | ||
--require ./spec/helpers/client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
FROM ruby:2.6 | ||
|
||
COPY Gemfile* ./ | ||
RUN gem install bundler && bundle install --jobs=3 --retry=3 | ||
|
||
RUN apt-get -q update && apt-get -qy install netcat | ||
RUN wget https://raw.githubusercontent.com/eficode/wait-for/v2.2.0/wait-for && chmod +x wait-for | ||
|
||
COPY .rspec . | ||
CMD ["bundle", "exec", "rspec"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Gemfile | ||
source "https://rubygems.org" | ||
|
||
gem "rspec" | ||
gem 'rest-client' | ||
gem 'nokogiri' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
diff-lcs (1.4.4) | ||
domain_name (0.5.20190701) | ||
unf (>= 0.0.5, < 1.0.0) | ||
http-accept (1.7.0) | ||
http-cookie (1.0.4) | ||
domain_name (~> 0.5) | ||
mime-types (3.4.1) | ||
mime-types-data (~> 3.2015) | ||
mime-types-data (3.2021.1115) | ||
netrc (0.11.0) | ||
rest-client (2.1.0) | ||
http-accept (>= 1.7.0, < 2.0) | ||
http-cookie (>= 1.0.2, < 2.0) | ||
mime-types (>= 1.16, < 4.0) | ||
netrc (~> 0.8) | ||
rspec (3.10.0) | ||
rspec-core (~> 3.10.0) | ||
rspec-expectations (~> 3.10.0) | ||
rspec-mocks (~> 3.10.0) | ||
rspec-core (3.10.1) | ||
rspec-support (~> 3.10.0) | ||
rspec-expectations (3.10.1) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.10.0) | ||
rspec-mocks (3.10.2) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.10.0) | ||
rspec-support (3.10.3) | ||
unf (0.1.4) | ||
unf_ext | ||
unf_ext (0.0.8) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
rest-client | ||
rspec | ||
|
||
BUNDLED WITH | ||
1.17.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
require 'json' | ||
|
||
describe "api" do | ||
GATEWAY_BASE_URL = "http://sut:8080/api" | ||
context "/_" do | ||
context "get" do | ||
result = Client.get "#{GATEWAY_BASE_URL}/_" | ||
it "return 200" do | ||
expect(result.code).to eq(200) | ||
end | ||
it "return OK" do | ||
expect(result.body).to eq("OK") | ||
end | ||
end | ||
end | ||
context "/config" do | ||
context "get" do | ||
result = Client.get "#{GATEWAY_BASE_URL}/config" | ||
it "return 200" do | ||
expect(result.code).to eq(200) | ||
end | ||
it "response header content-type is application/json" do | ||
expect(result.headers[:content_type]).to eq("application/json") | ||
end | ||
it "config is valid json" do | ||
expect(JSON.parse(result.body)['provider']).to eq("basic") | ||
end | ||
end | ||
context "/management" do | ||
context "get properties" do | ||
result = Client.get "#{GATEWAY_BASE_URL}/management/properties", {'x-api-key' => 'demo-key'} | ||
it "return 200" do | ||
expect(result.code).to eq(200) | ||
end | ||
it "X-Forwarded-For header is set" do | ||
expect(result.body).to include("X-Forwarded-For") | ||
end | ||
end | ||
context "get healthcheck" do | ||
result = Client.get "#{GATEWAY_BASE_URL}/management/gtg" | ||
it "return 200" do | ||
expect(result.code).to eq(200) | ||
end | ||
it "good-to-go is OK" do | ||
expect(result.body).to eq("OK") | ||
end | ||
it "response header does not contain nginx version" do | ||
expect(result.headers[:server]).to eq("nginx") | ||
end | ||
end | ||
end | ||
context "/alerts" do | ||
context "get without auth" do | ||
result = Client.get "#{GATEWAY_BASE_URL}/alerts" | ||
it "return 401" do | ||
expect(result.code).to eq(401) | ||
end | ||
end | ||
context "get" do | ||
result = Client.get "#{GATEWAY_BASE_URL}/alerts?api-key=demo-key" | ||
it "return 200" do | ||
expect(result.code).to eq(200) | ||
end | ||
it "total is 0" do | ||
expect(JSON.parse(result.body)['total']).to eq(0) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require 'rest-client' | ||
|
||
module Client | ||
include RestClient | ||
|
||
def self.get(*args) | ||
begin | ||
RestClient.get(*args) | ||
rescue => e | ||
e.response | ||
end | ||
end | ||
|
||
def self.post(*args) | ||
begin | ||
RestClient.post(*args) | ||
rescue => e | ||
e.response | ||
end | ||
end | ||
|
||
def self.put(*args) | ||
begin | ||
RestClient.put(*args) | ||
rescue => e | ||
e.response | ||
end | ||
end | ||
|
||
def self.delete(*args) | ||
begin | ||
RestClient.delete(*args) | ||
rescue => e | ||
e.response | ||
end | ||
end | ||
end |
Oops, something went wrong.