Merge pull request #13083 from nik9000/bats_less_skip

Clean up more bats tests
This commit is contained in:
Nik Everett 2015-09-02 08:45:15 -04:00
commit 467a459f95
5 changed files with 74 additions and 183 deletions

View File

@ -34,50 +34,39 @@ load packaging_test_utils
# Cleans everything for the 1st execution # Cleans everything for the 1st execution
setup() { setup() {
if [ "$BATS_TEST_NUMBER" -eq 1 ]; then skip_not_dpkg
clean_before_test
fi
} }
################################## ##################################
# Install DEB package # Install DEB package
################################## ##################################
@test "[DEB] dpkg command is available" { @test "[DEB] dpkg command is available" {
skip_not_dpkg clean_before_test
run dpkg --version dpkg --version
[ "$status" -eq 0 ]
} }
@test "[DEB] package is available" { @test "[DEB] package is available" {
skip_not_dpkg
count=$(find . -type f -name 'elastic*.deb' | wc -l) count=$(find . -type f -name 'elastic*.deb' | wc -l)
[ "$count" -eq 1 ] [ "$count" -eq 1 ]
} }
@test "[DEB] package is not installed" { @test "[DEB] package is not installed" {
skip_not_dpkg run dpkg -s 'elasticsearch'
run dpkg -s 'elasticsearch' >&2
[ "$status" -eq 1 ] [ "$status" -eq 1 ]
} }
@test "[DEB] install package" { @test "[DEB] install package" {
skip_not_dpkg dpkg -i elasticsearch*.deb
run dpkg -i elasticsearch*.deb >&2
[ "$status" -eq 0 ]
} }
@test "[DEB] package is installed" { @test "[DEB] package is installed" {
skip_not_dpkg dpkg -s 'elasticsearch'
run dpkg -s 'elasticsearch' >&2
[ "$status" -eq 0 ]
} }
################################## ##################################
# Check that the package is correctly installed # Check that the package is correctly installed
################################## ##################################
@test "[DEB] verify package installation" { @test "[DEB] verify package installation" {
skip_not_dpkg
verify_package_installation verify_package_installation
} }
@ -85,8 +74,6 @@ setup() {
# Check that Elasticsearch is working # Check that Elasticsearch is working
################################## ##################################
@test "[DEB] test elasticsearch" { @test "[DEB] test elasticsearch" {
skip_not_dpkg
start_elasticsearch_service start_elasticsearch_service
run_elasticsearch_tests run_elasticsearch_tests
@ -96,21 +83,16 @@ setup() {
# Uninstall DEB package # Uninstall DEB package
################################## ##################################
@test "[DEB] remove package" { @test "[DEB] remove package" {
skip_not_dpkg dpkg -r 'elasticsearch'
run dpkg -r 'elasticsearch' >&2
[ "$status" -eq 0 ]
} }
@test "[DEB] package has been removed" { @test "[DEB] package has been removed" {
skip_not_dpkg run dpkg -s 'elasticsearch'
run dpkg -s 'elasticsearch' >&2
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
echo "$output" | grep -i "status" | grep -i "deinstall ok" echo "$output" | grep -i "status" | grep -i "deinstall ok"
} }
@test "[DEB] verify package removal" { @test "[DEB] verify package removal" {
skip_not_dpkg
# The removal must stop the service # The removal must stop the service
count=$(ps | grep Elasticsearch | wc -l) count=$(ps | grep Elasticsearch | wc -l)
[ "$count" -eq 0 ] [ "$count" -eq 0 ]
@ -146,14 +128,10 @@ setup() {
} }
@test "[DEB] purge package" { @test "[DEB] purge package" {
skip_not_dpkg dpkg --purge 'elasticsearch'
run dpkg --purge 'elasticsearch' >&2
[ "$status" -eq 0 ]
} }
@test "[DEB] verify package purge" { @test "[DEB] verify package purge" {
skip_not_dpkg
# all remaining files are deleted by the purge # all remaining files are deleted by the purge
assert_file_not_exist "/etc/elasticsearch" assert_file_not_exist "/etc/elasticsearch"
assert_file_not_exist "/etc/elasticsearch/elasticsearch.yml" assert_file_not_exist "/etc/elasticsearch/elasticsearch.yml"
@ -171,7 +149,6 @@ setup() {
} }
@test "[DEB] package has been completly removed" { @test "[DEB] package has been completly removed" {
skip_not_dpkg run dpkg -s 'elasticsearch'
run dpkg -s 'elasticsearch' >&2
[ "$status" -eq 1 ] [ "$status" -eq 1 ]
} }

View File

@ -33,50 +33,39 @@ load packaging_test_utils
# Cleans everything for the 1st execution # Cleans everything for the 1st execution
setup() { setup() {
if [ "$BATS_TEST_NUMBER" -eq 1 ]; then skip_not_rpm
clean_before_test
fi
} }
################################## ##################################
# Install RPM package # Install RPM package
################################## ##################################
@test "[RPM] rpm command is available" { @test "[RPM] rpm command is available" {
skip_not_rpm clean_before_test
run rpm --version rpm --version
[ "$status" -eq 0 ]
} }
@test "[RPM] package is available" { @test "[RPM] package is available" {
skip_not_rpm
count=$(find . -type f -name 'elastic*.rpm' | wc -l) count=$(find . -type f -name 'elastic*.rpm' | wc -l)
[ "$count" -eq 1 ] [ "$count" -eq 1 ]
} }
@test "[RPM] package is not installed" { @test "[RPM] package is not installed" {
skip_not_rpm run rpm -qe 'elasticsearch'
run rpm -qe 'elasticsearch' >&2
[ "$status" -eq 1 ] [ "$status" -eq 1 ]
} }
@test "[RPM] install package" { @test "[RPM] install package" {
skip_not_rpm rpm -i elasticsearch*.rpm
run rpm -i elasticsearch*.rpm >&2
[ "$status" -eq 0 ]
} }
@test "[RPM] package is installed" { @test "[RPM] package is installed" {
skip_not_rpm rpm -qe 'elasticsearch'
run rpm -qe 'elasticsearch' >&2
[ "$status" -eq 0 ]
} }
################################## ##################################
# Check that the package is correctly installed # Check that the package is correctly installed
################################## ##################################
@test "[RPM] verify package installation" { @test "[RPM] verify package installation" {
skip_not_rpm
verify_package_installation verify_package_installation
} }
@ -84,8 +73,6 @@ setup() {
# Check that Elasticsearch is working # Check that Elasticsearch is working
################################## ##################################
@test "[RPM] test elasticsearch" { @test "[RPM] test elasticsearch" {
skip_not_rpm
start_elasticsearch_service start_elasticsearch_service
run_elasticsearch_tests run_elasticsearch_tests
@ -95,20 +82,15 @@ setup() {
# Uninstall RPM package # Uninstall RPM package
################################## ##################################
@test "[RPM] remove package" { @test "[RPM] remove package" {
skip_not_rpm rpm -e 'elasticsearch'
run rpm -e 'elasticsearch' >&2
[ "$status" -eq 0 ]
} }
@test "[RPM] package has been removed" { @test "[RPM] package has been removed" {
skip_not_rpm run rpm -qe 'elasticsearch'
run rpm -qe 'elasticsearch' >&2
[ "$status" -eq 1 ] [ "$status" -eq 1 ]
} }
@test "[RPM] verify package removal" { @test "[RPM] verify package removal" {
skip_not_rpm
# The removal must stop the service # The removal must stop the service
count=$(ps | grep Elasticsearch | wc -l) count=$(ps | grep Elasticsearch | wc -l)
[ "$count" -eq 0 ] [ "$count" -eq 0 ]

View File

@ -33,42 +33,27 @@ load packaging_test_utils
# Cleans everything for the 1st execution # Cleans everything for the 1st execution
setup() { setup() {
if [ "$BATS_TEST_NUMBER" -eq 1 ]; then skip_not_systemd
clean_before_test skip_not_dpkg_or_rpm
fi
# Installs a package before test
if is_dpkg; then
dpkg -i elasticsearch*.deb >&2 || true
fi
if is_rpm; then
rpm -i elasticsearch*.rpm >&2 || true
fi
} }
@test "[SYSTEMD] daemon reload" { @test "[SYSTEMD] install elasticsearch" {
skip_not_systemd clean_before_test
install_package
}
run systemctl daemon-reload @test "[SYSTEMD] daemon reload after install" {
[ "$status" -eq 0 ] systemctl daemon-reload
} }
@test "[SYSTEMD] enable" { @test "[SYSTEMD] enable" {
skip_not_systemd systemctl enable elasticsearch.service
run systemctl enable elasticsearch.service systemctl is-enabled elasticsearch.service
[ "$status" -eq 0 ]
run systemctl is-enabled elasticsearch.service
[ "$status" -eq 0 ]
} }
@test "[SYSTEMD] start" { @test "[SYSTEMD] start" {
skip_not_systemd systemctl start elasticsearch.service
run systemctl start elasticsearch.service
[ "$status" -eq 0 ]
wait_for_elasticsearch_status wait_for_elasticsearch_status
@ -76,72 +61,53 @@ setup() {
} }
@test "[SYSTEMD] start (running)" { @test "[SYSTEMD] start (running)" {
skip_not_systemd systemctl start elasticsearch.service
run systemctl start elasticsearch.service
[ "$status" -eq 0 ]
} }
@test "[SYSTEMD] is active (running)" { @test "[SYSTEMD] is active (running)" {
skip_not_systemd
run systemctl is-active elasticsearch.service run systemctl is-active elasticsearch.service
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[ "$output" = "active" ] [ "$output" = "active" ]
} }
@test "[SYSTEMD] status (running)" { @test "[SYSTEMD] status (running)" {
skip_not_systemd systemctl status elasticsearch.service
run systemctl status elasticsearch.service
[ "$status" -eq 0 ]
} }
################################## ##################################
# Check that Elasticsearch is working # Check that Elasticsearch is working
################################## ##################################
@test "[SYSTEMD] test elasticsearch" { @test "[SYSTEMD] test elasticsearch" {
skip_not_systemd
run_elasticsearch_tests run_elasticsearch_tests
} }
@test "[SYSTEMD] restart" { @test "[SYSTEMD] restart" {
skip_not_systemd systemctl restart elasticsearch.service
run systemctl restart elasticsearch.service
[ "$status" -eq 0 ]
wait_for_elasticsearch_status wait_for_elasticsearch_status
run service elasticsearch status service elasticsearch status
[ "$status" -eq 0 ]
} }
@test "[SYSTEMD] stop (running)" { @test "[SYSTEMD] stop (running)" {
skip_not_systemd systemctl stop elasticsearch.service
run systemctl stop elasticsearch.service
[ "$status" -eq 0 ]
run systemctl status elasticsearch.service run systemctl status elasticsearch.service
[ "$status" -eq 3 ] || "Expected exit code 3 meaning stopped"
echo "$output" | grep "Active:" | grep "inactive" echo "$output" | grep "Active:" | grep "inactive"
} }
@test "[SYSTEMD] stop (stopped)" { @test "[SYSTEMD] stop (stopped)" {
skip_not_systemd systemctl stop elasticsearch.service
run systemctl stop elasticsearch.service
[ "$status" -eq 0 ]
run systemctl status elasticsearch.service run systemctl status elasticsearch.service
[ "$status" -eq 3 ] || "Expected exit code 3 meaning stopped"
echo "$output" | grep "Active:" | grep "inactive" echo "$output" | grep "Active:" | grep "inactive"
} }
@test "[SYSTEMD] status (stopped)" { @test "[SYSTEMD] status (stopped)" {
skip_not_systemd
run systemctl status elasticsearch.service run systemctl status elasticsearch.service
[ "$status" -eq 3 ] || "Expected exit code 3 meaning stopped"
echo "$output" | grep "Active:" | grep "inactive" echo "$output" | grep "Active:" | grep "inactive"
} }
@ -150,21 +116,15 @@ setup() {
# but it should not block ES from starting # but it should not block ES from starting
# see https://github.com/elastic/elasticsearch/issues/11594 # see https://github.com/elastic/elasticsearch/issues/11594
@test "[SYSTEMD] delete PID_DIR and restart" { @test "[SYSTEMD] delete PID_DIR and restart" {
skip_not_systemd rm -rf /var/run/elasticsearch
run rm -rf /var/run/elasticsearch systemd-tmpfiles --create
[ "$status" -eq 0 ]
run systemd-tmpfiles --create systemctl start elasticsearch.service
[ "$status" -eq 0 ]
run systemctl start elasticsearch.service
[ "$status" -eq 0 ]
wait_for_elasticsearch_status wait_for_elasticsearch_status
assert_file_exist "/var/run/elasticsearch/elasticsearch.pid" assert_file_exist "/var/run/elasticsearch/elasticsearch.pid"
run systemctl stop elasticsearch.service systemctl stop elasticsearch.service
[ "$status" -eq 0 ] }
}

View File

@ -33,24 +33,17 @@ load packaging_test_utils
# Cleans everything for the 1st execution # Cleans everything for the 1st execution
setup() { setup() {
if [ "$BATS_TEST_NUMBER" -eq 1 ]; then skip_not_sysvinit
clean_before_test skip_not_dpkg_or_rpm
fi }
# Installs a package before test @test "[INIT.D] install elasticsearch" {
if is_dpkg; then clean_before_test
dpkg -i elasticsearch*.deb >&2 || true install_package
fi
if is_rpm; then
rpm -i elasticsearch*.rpm >&2 || true
fi
} }
@test "[INIT.D] start" { @test "[INIT.D] start" {
skip_not_sysvinit service elasticsearch start
run service elasticsearch start
[ "$status" -eq 0 ]
wait_for_elasticsearch_status wait_for_elasticsearch_status
@ -58,44 +51,29 @@ setup() {
} }
@test "[INIT.D] status (running)" { @test "[INIT.D] status (running)" {
skip_not_sysvinit service elasticsearch status
run service elasticsearch status
[ "$status" -eq 0 ]
} }
################################## ##################################
# Check that Elasticsearch is working # Check that Elasticsearch is working
################################## ##################################
@test "[INIT.D] test elasticsearch" { @test "[INIT.D] test elasticsearch" {
skip_not_sysvinit
run_elasticsearch_tests run_elasticsearch_tests
} }
@test "[INIT.D] restart" { @test "[INIT.D] restart" {
skip_not_sysvinit service elasticsearch restart
run service elasticsearch restart
[ "$status" -eq 0 ]
wait_for_elasticsearch_status wait_for_elasticsearch_status
run service elasticsearch status service elasticsearch status
[ "$status" -eq 0 ]
} }
@test "[INIT.D] stop (running)" { @test "[INIT.D] stop (running)" {
skip_not_sysvinit service elasticsearch stop
run service elasticsearch stop
[ "$status" -eq 0 ]
} }
@test "[INIT.D] status (stopped)" { @test "[INIT.D] status (stopped)" {
skip_not_sysvinit
run service elasticsearch status run service elasticsearch status
# precise returns 4, trusty 3 # precise returns 4, trusty 3
[ "$status" -eq 3 ] || [ "$status" -eq 4 ] [ "$status" -eq 3 ] || [ "$status" -eq 4 ]
@ -106,19 +84,13 @@ setup() {
# but it should not block ES from starting # but it should not block ES from starting
# see https://github.com/elastic/elasticsearch/issues/11594 # see https://github.com/elastic/elasticsearch/issues/11594
@test "[INIT.D] delete PID_DIR and restart" { @test "[INIT.D] delete PID_DIR and restart" {
skip_not_sysvinit rm -rf /var/run/elasticsearch
run rm -rf /var/run/elasticsearch service elasticsearch start
[ "$status" -eq 0 ]
run service elasticsearch start
[ "$status" -eq 0 ]
wait_for_elasticsearch_status wait_for_elasticsearch_status
assert_file_exist "/var/run/elasticsearch/elasticsearch.pid" assert_file_exist "/var/run/elasticsearch/elasticsearch.pid"
run service elasticsearch stop service elasticsearch stop
[ "$status" -eq 0 ]
} }

View File

@ -79,16 +79,16 @@ is_rpm() {
# Skip test if the 'dpkg' command is not supported # Skip test if the 'dpkg' command is not supported
skip_not_dpkg() { skip_not_dpkg() {
if [ ! -x "`which dpkg 2>/dev/null`" ]; then is_dpkg || skip "dpkg is not supported"
skip "dpkg is not supported"
fi
} }
# Skip test if the 'rpm' command is not supported # Skip test if the 'rpm' command is not supported
skip_not_rpm() { skip_not_rpm() {
if [ ! -x "`which rpm 2>/dev/null`" ]; then is_rpm || skip "rpm is not supported"
skip "rpm is not supported" }
fi
skip_not_dpkg_or_rpm() {
is_dpkg || is_rpm || skip "only dpkg or rpm systems are supported"
} }
# Returns 0 if the system supports Systemd # Returns 0 if the system supports Systemd
@ -177,17 +177,6 @@ assert_output() {
echo "$output" | grep -E "$1" echo "$output" | grep -E "$1"
} }
# Install the rpm or deb package
install_package() {
if is_rpm; then
rpm -i elasticsearch*.rpm
elif is_dpkg; then
dpkg -i elasticsearch*.deb
else
skip "Only rpm or deb supported"
fi
}
# Checks that all directories & files are correctly installed # Checks that all directories & files are correctly installed
# after a package (deb/rpm) install # after a package (deb/rpm) install
verify_package_installation() { verify_package_installation() {
@ -243,6 +232,17 @@ verify_package_installation() {
fi fi
} }
# Install the rpm or deb package
install_package() {
if is_rpm; then
rpm -i elasticsearch*.rpm
elif is_dpkg; then
dpkg -i elasticsearch*.deb
else
skip "Only rpm or deb supported"
fi
}
# Checks that all directories & files are correctly installed # Checks that all directories & files are correctly installed
# after a archive (tar.gz/zip) install # after a archive (tar.gz/zip) install
verify_archive_installation() { verify_archive_installation() {