Skip to content

Commit

Permalink
blackbox-testing install and uninstall (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
jancajthaml authored Mar 18, 2019
1 parent 85159d2 commit e4058a3
Show file tree
Hide file tree
Showing 20 changed files with 214 additions and 225 deletions.
3 changes: 3 additions & 0 deletions bbtest/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ RUN \
exit 1 ; \
fi

RUN find . /etc/bbtest/packages -type f -name 'vault_*_amd64.deb' | \
xargs -I {} mv {} /etc/bbtest/packages/vault.deb

RUN apt-get update && \
apt-get install -y \
init-system-helpers>=1.18~ \
Expand Down
84 changes: 41 additions & 43 deletions bbtest/features/api_account.feature → bbtest/features/api.feature
Original file line number Diff line number Diff line change
@@ -1,54 +1,76 @@
Feature: Account API test
Feature: REST

Scenario: Account API - get accounts when application is from scratch
Given tenant API is onbdoarded
And vault is reconfigured with
Scenario: Tenant API
Given vault is reconfigured with
"""
LOG_LEVEL=DEBUG
HTTP_PORT=443
"""

When I request curl GET https://localhost/account/API
When I request curl GET https://localhost/tenant
Then curl responds with 200
"""
[]
"""

Scenario: Account API - account doesn't exist
Given tenant API is onbdoarded
And vault is reconfigured with
When I request curl POST https://localhost/tenant/APITESTA
Then curl responds with 200
"""
LOG_LEVEL=DEBUG
HTTP_PORT=443
{}
"""

When I request curl GET https://localhost/account/API/xxx
Then curl responds with 404
When I request curl POST https://localhost/tenant/APITESTB
Then curl responds with 200
"""
{}
"""

Scenario: Account API - request for account of non-existent vault
Given vault is reconfigured with
When I request curl GET https://localhost/tenant
Then curl responds with 200
"""
LOG_LEVEL=DEBUG
HTTP_PORT=443
[
"APITESTB"
]
"""

When I request curl GET https://localhost/account/nothing/xxx
Then curl responds with 504
When I request curl POST https://localhost/tenant/APITESTC
Then curl responds with 200
"""
{}
"""

When I request curl DELETE https://localhost/tenant/APITESTC
Then curl responds with 200
"""
{}
"""

Scenario: Account API - create non existant account
Scenario: Account API
Given tenant API is onbdoarded
And vault is reconfigured with
"""
LOG_LEVEL=DEBUG
HTTP_PORT=443
"""

When I request curl GET https://localhost/account/API
Then curl responds with 200
"""
[]
"""

When I request curl GET https://localhost/account/API/xxx
Then curl responds with 404
"""
{}
"""

When I request curl GET https://localhost/account/nothing/xxx
Then curl responds with 504
"""
{}
"""

When I request curl POST https://localhost/account/API
"""
{
Expand All @@ -62,14 +84,6 @@ Feature: Account API test
{}
"""

Scenario: Account API - account already exists
Given tenant API is onbdoarded
And vault is reconfigured with
"""
LOG_LEVEL=DEBUG
HTTP_PORT=443
"""

When I request curl POST https://localhost/account/API
"""
{
Expand All @@ -96,14 +110,6 @@ Feature: Account API test
{}
"""

Scenario: Account API - get accounts
Given tenant API is onbdoarded
And vault is reconfigured with
"""
LOG_LEVEL=DEBUG
HTTP_PORT=443
"""

When I request curl POST https://localhost/account/API
"""
{
Expand All @@ -123,14 +129,6 @@ Feature: Account API test
]
"""

Scenario: Account API - get account balance
Given tenant API is onbdoarded
And vault is reconfigured with
"""
LOG_LEVEL=DEBUG
HTTP_PORT=443
"""

When I request curl POST https://localhost/account/API
"""
{
Expand Down
67 changes: 0 additions & 67 deletions bbtest/features/api_tenant.feature

This file was deleted.

7 changes: 0 additions & 7 deletions bbtest/features/configuration.feature
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
Feature: Service can be configured

Scenario: properly installed debian package
Given tenant CONFIGURATION is onbdoarded
Then systemctl contains following
"""
vault-unit@CONFIGURATION.service
"""

Scenario: configure log level
Given tenant CONFIGURATION is onbdoarded
And vault is reconfigured with
Expand Down
11 changes: 11 additions & 0 deletions bbtest/features/install.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@install
Feature: Install package

Scenario: install
Given package "vault.deb" is installed
Then systemctl contains following
"""
vault.service
vault.path
vault-rest.service
"""
11 changes: 11 additions & 0 deletions bbtest/features/uninstall.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@uninstall
Feature: Unnstall package

Scenario: uninstall
Given package "vault" is uninstalled
Then systemctl does not contains following
"""
vault.service
vault.path
vault-rest.service
"""
43 changes: 15 additions & 28 deletions bbtest/spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@
RSpec.configure do |config|
config.raise_error_for_unimplemented_steps = true
config.color = true
config.fail_fast = true

Dir.glob("./helpers/*_helper.rb") { |f| load f }
config.include EventuallyHelper, :type => :feature
config.include JournalHelper, :type => :feature
Dir.glob("./steps/*_steps.rb") { |f| load f, true }

config.register_ordering(:global) do |items|
(install, others) = items.partition { |spec| spec.metadata[:install] }
(uninstall, others) = others.partition { |spec| spec.metadata[:uninstall] }

install + others.shuffle + uninstall
end

config.before(:suite) do |_|
print "[ suite starting ]\n"

Expand All @@ -23,20 +31,6 @@
%x(rm -rf #{folder}/*)
}

print "[ installing package ]\n"

%x(find /etc/bbtest/packages -type f -name 'vault_*_amd64.deb')
.split("\n")
.map(&:strip)
.reject { |x| x.empty? }
.each { |package|
IO.popen("apt-get -y install -f #{package}") do |io|
while (line = io.gets) do
puts line
end
end
}

print "[ suite started ]\n"
end

Expand All @@ -62,22 +56,15 @@
config.after(:suite) do |_|
print "\n[ suite ending ]\n"

ids = %x(systemctl -a -t service --no-legend | awk '{ print $1 }')

if $?
ids = ids.split("\n").map(&:strip).reject { |x|
x.empty? || !x.start_with?("vault")
}.map { |x| x.chomp(".service") }
else
ids = []
end

ids.each { |e|
%x(journalctl -o short-precise -u #{e} --no-pager > /reports/#{e}.log 2>&1)
[
"vault-rest",
"vault",
].each { |e|
%x(journalctl -o short-precise -u #{e}.service --no-pager > /reports/#{e}.log 2>&1)
%x(systemctl stop #{e} 2>&1)
%x(systemctl disable #{e} 2>&1)
%x(journalctl -o short-precise -u #{e} --no-pager > /reports/#{e}.log 2>&1)
} unless ids.empty?
%x(journalctl -o short-precise -u #{e}.service --no-pager > /reports/#{e}.log 2>&1)
}

LakeMock.stop()

Expand Down
18 changes: 16 additions & 2 deletions bbtest/steps/debian_steps.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@

step "package :package is installed" do |package|
out = %x(apt-get -y install -f /etc/bbtest/packages/#{package})
expect($?).to be_success, out

expect(File.file?("/etc/init/vault.conf")).to be(true)
end

step "package :package is uninstalled" do |package|
out = %x(apt-get -y remove #{package})
expect($?).to be_success, out

expect(File.file?("/etc/init/vault.conf")).to be(false)
end

step "systemctl contains following" do |packages|
items = packages.split("\n").map(&:strip).reject(&:empty?)

eventually() {
items.each { |item|
units = %x(systemctl -a -t service --no-legend | awk '{ print $1 }')
units = %x(systemctl list-units --no-legend | awk '{ print $1 }')
units = units.split("\n").map(&:strip).reject(&:empty?)
subset = units.reject { |x| !x.include?(item) }
expect(subset).not_to be_empty, "\"#{item}\" was not found in #{units}"
Expand All @@ -16,7 +30,7 @@
items = packages.split("\n").map(&:strip).reject(&:empty?)

items.each { |item|
units = %x(systemctl -a -t service --no-legend | awk '{ print $1 }')
units = %x(systemctl list-units --no-legend | awk '{ print $1 }')
units = units.split("\n").map(&:strip).reject(&:empty?)
subset = units.reject { |x| !x.include?(item) }
expect(subset).to be_empty, "#{item} was found not found in #{units}"
Expand Down
2 changes: 1 addition & 1 deletion packaging/debian_amd64/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: vault
Version: 1.2.0+better-packaging-and-control
Version: 1.2.0+test-install-uninstall
Architecture: amd64
Maintainer: Jan Cajthaml <jan.cajthaml@gmail.com>
Depends: init-system-helpers (>= 1.18~), libzmq5 (>= 4.2.1~), openssl (>= 1.1~)
Expand Down
19 changes: 12 additions & 7 deletions packaging/debian_amd64/DEBIAN/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ case "$1" in

configure)
if [ -f "/etc/init/vault.conf" ] ; then
systemctl unmask vault-rest.service >/dev/null
systemctl enable vault-rest.service >/dev/null

systemctl unmask vault-unit.service >/dev/null

systemctl unmask vault.service >/dev/null
systemctl enable vault.service >/dev/null
systemctl unmask \
vault.path \
vault-unit.service \
vault-rest.service \
vault.service \
>/dev/null

systemctl enable \
vault.path \
vault-rest.service \
vault.service \
>/dev/null

(systemctl start vault.service >/dev/null || :)
else
Expand Down
Loading

0 comments on commit e4058a3

Please sign in to comment.