Refactor 'mixer build' bats tests

This patch significantly overhauls the BATS tests for building mixes,
with the goal of reducing redundancy and increasing accuracy.

Each of the following concepts is only tested once:
- Building a mix with a full, real upstream bundle
- Updating the version of a mix (technically tested twice)
- Adding a bundle to a mix
- Removing a bundle from a mix
- Building a mix with a custom local bundle
- Adding a custom package to an upstream bundle
- Adding an upstream package to a custom bundle

Because all but one of the tests use stripped down versions of upstream
bundles for efficiency, they all test:
- Building a mix with a local, edited upstream bundle

This dramatically reduces the number of actual builds that occur.

The test descriptions accurately describe what the tests are actually
doing, and they report if they are using stripped down versions of upstream
bundles.

Signed-off-by: Kevin C. Wells <kevin.c.wells@intel.com>
This commit is contained in:
Kevin C. Wells
2018-03-22 17:26:40 -07:00
committed by tmarcu
parent a0771473ab
commit eb4a9b7d6d
34 changed files with 184 additions and 241 deletions
+29 -31
View File
@@ -3,41 +3,41 @@
# This library defines functions to use in the BATS test files during a local
# test run with 'make check'.
export cachedir="$HOME/.cache/mixer-tests"
logdir="$BATS_TEST_DIRNAME/logs"
BUNDLE_DIR="$BATS_TEST_DIRNAME/local-bundles"
LOGDIR="$BATS_TEST_DIRNAME/logs"
LOCAL_BUNDLE_DIR="$BATS_TEST_DIRNAME/local-bundles"
CLRVER=$(curl https://download.clearlinux.org/latest)
CLR_BUNDLES="$BATS_TEST_DIRNAME/upstream-bundles/clr-bundles-$CLRVER/bundles"
BUNDLE_LIST="$BATS_TEST_DIRNAME/mixbundles"
mkdir -p $cachedir
mkdir -p $logdir
mkdir -p $LOGDIR
setup_builder_conf() {
:
global_setup() {
: # Put content here for it to run for all tests
}
localize_builder_conf() {
echo "LOCAL_RPM_DIR = $BATS_TEST_DIRNAME/local-rpms
LOCAL_REPO_DIR = $BATS_TEST_DIRNAME/local-yum" | sudo tee -a $BATS_TEST_DIRNAME/builder.conf > /dev/null
echo -e "LOCAL_RPM_DIR=$BATS_TEST_DIRNAME/local-rpms\nLOCAL_REPO_DIR=$BATS_TEST_DIRNAME/local-yum" >> $BATS_TEST_DIRNAME/builder.conf
}
mixer-init-versions() {
sudo touch $BATS_TEST_DIRNAME/mixbundles
sudo -E mixer init --clear-version $1 --mix-version $2 --new-swupd
sudo sed -i 's/os-core-update/os-core/' $BATS_TEST_DIRNAME/builder.conf
# Initializes a mix with the desired versions. Then for efficiency converts
# builder.conf to use os-core for the "update bundle", strips os-core to just
# the filesystem, and adds only os-core to the mix
mixer-init-stripped-down() {
touch $BATS_TEST_DIRNAME/mixbundles
mixer init --clear-version $1 --mix-version $2 --new-swupd
sed -i 's/os-core-update/os-core/' $BATS_TEST_DIRNAME/builder.conf
echo "filesystem" > $LOCAL_BUNDLE_DIR/os-core
mixer bundle add os-core
}
clean-bundle-dir() {
sudo rm -rf $BUNDLE_DIR/* $BATS_TEST_DIRNAME/mixbundles
echo -e "filesystem\n" | sudo tee $BUNDLE_DIR/os-core > /dev/null
sudo mixer bundle add os-core
mixer-versions-update() {
mixer versions update --mix-version $1
}
mixer-build-bundles() {
sudo -E mixer build bundles --config $BATS_TEST_DIRNAME/builder.conf --new-swupd --new-chroots
}
mixer-create-update() {
mixer-build-update() {
sudo -E mixer build update --config $BATS_TEST_DIRNAME/builder.conf --new-swupd
}
@@ -46,32 +46,30 @@ mixer-add-rpms() {
sudo -E mixer add-rpms --config $BATS_TEST_DIRNAME/builder.conf --new-swupd
}
add-bundle() {
sudo touch $BUNDLE_DIR/$1
create-empty-local-bundle() {
touch $LOCAL_BUNDLE_DIR/$1
}
add-package() {
echo $1 | sudo tee -a $BUNDLE_DIR/$2 > /dev/null
sudo mixer bundle add $2
add-package-to-local-bundle() {
echo $1 >> $LOCAL_BUNDLE_DIR/$2
}
add-clear-bundle() {
sudo cp $CLR_BUNDLES/$1 $BUNDLE_DIR
sudo mixer bundle add $1
remove-package-from-local-bundle() {
sed -i "/$1/d" $LOCAL_BUNDLE_DIR/$2
}
remove-bundle() {
sudo sed -i "/$1/d" $BUNDLE_LIST
mixer-bundle-add() {
mixer bundle add $1
}
remove-package() {
sudo sed -i "/$1/d" $BUNDLE_DIR/$2
mixer-bundle-remove() {
mixer bundle remove $1
}
download-rpm() {
mkdir -p $BATS_TEST_DIRNAME/local-rpms
pushd $BATS_TEST_DIRNAME/local-rpms
sudo curl -LO $1
curl -LO $1
popd
}
+1 -1
View File
@@ -1,4 +1,4 @@
01-bundle-commands
====================
==================
This test case tests the 'mixer bundle' commands for adding and removing bundles
from your mix, and for manipulating upstream and local bundle definition files.
+4
View File
@@ -3,6 +3,10 @@
# shared test functions
load ../../lib/mixerlib
setup() {
global_setup
}
@test "Initialize a mix at version 10" {
mixer init --clear-version $CLRVER --mix-version 10
[[ -f $BATS_TEST_DIRNAME/builder.conf ]]
@@ -1,4 +0,0 @@
01-create-simple-mix
====================
This test case creates a mix with no custom changes, simply creating an
initial version 10, bumping the version to 20, and creating another update.
-22
View File
@@ -1,22 +0,0 @@
#!/usr/bin/env bats
# shared test functions
load ../../lib/mixerlib
setup() {
setup_builder_conf
}
@test "Create initial mix 10" {
mixer-init-versions $CLRVER 10
clean-bundle-dir
mixer-build-bundles
mixer-create-update
}
@test "Create version 20 with no changes" {
mixer-init-versions $CLRVER 20
mixer-build-bundles
mixer-create-update > $BATS_TEST_DIRNAME/create_update20.log
}
# vi: ft=sh ts=8 sw=2 sts=2 et tw=80
@@ -0,0 +1,4 @@
02-create-mix-with-upstream-bundles
===================================
This test case creates a mix with an unchanged upstream bundle. The default
config is updated to support building a mix with just os-core.
+21
View File
@@ -0,0 +1,21 @@
#!/usr/bin/env bats
# shared test functions
load ../../lib/mixerlib
setup() {
global_setup
}
@test "Create mix 10 with real clear bundle" {
mixer init --clear-version $CLRVER --mix-version 10
rm -f $BATS_TEST_DIRNAME/mixbundles # Wipe out default bundles
mixer bundle add os-core # Add real os-core from upstream
sed -i 's/os-core-update/os-core/' $BATS_TEST_DIRNAME/builder.conf # Patch default builder.conf
mixer-build-bundles > $LOGDIR/build_bundles.log
mixer-build-update > $LOGDIR/build_update.log
}
# vi: ft=sh ts=8 sw=2 sts=2 et tw=80
@@ -1,4 +0,0 @@
02-mix-clear-bundles
====================
This test creates an initial version 10, a version 20 with Clear bundles
added, and a version 30 with one of those bundles removed.
-33
View File
@@ -1,33 +0,0 @@
#!/usr/bin/env bats
# shared test functions
load ../../lib/mixerlib
setup() {
setup_builder_conf
}
@test "Create initial mix 10" {
mixer-init-versions $CLRVER 10
clean-bundle-dir
mixer-build-bundles
mixer-create-update > $BATS_TEST_DIRNAME/create_update-10.log
}
@test "Create version 20 with more Clear bundles" {
mixer-init-versions $CLRVER 20
add-bundle "editors"
add-package "joe" "editors"
add-bundle "os-core-update"
add-package "bsdiff" "os-core-update"
mixer-build-bundles
mixer-create-update > $BATS_TEST_DIRNAME/create_update-20.log
}
@test "Create version 30 with Clear bundle deleted" {
mixer-init-versions $CLRVER 30
remove-bundle "editors"
mixer-build-bundles
mixer-create-update > $BATS_TEST_DIRNAME/create_update-30.log
}
# vi: ft=sh ts=8 sw=2 sts=2 et tw=80
@@ -0,0 +1,5 @@
03-create-mix-bump-version-add-remove-bundles
=============================================
This test creates an initial version 10, a version 20 with upstream bundles
added, and a version 30 with one of those bundles removed. All bundles have been
stripped down for efficiency, and all content comes from upstream.
@@ -0,0 +1,38 @@
#!/usr/bin/env bats
# shared test functions
load ../../lib/mixerlib
setup() {
global_setup
}
@test "Create initial stripped down mix 10" {
mixer-init-stripped-down $CLRVER 10
mixer-build-bundles > $LOGDIR/build_bundles_10.log
mixer-build-update > $LOGDIR/build_update_10.log
}
@test "Create version 20 with more stripped down upstream bundles" {
mixer-versions-update 20
create-empty-local-bundle "editors"
add-package-to-local-bundle "joe" "editors"
mixer-bundle-add "editors"
create-empty-local-bundle "os-core-update"
add-package-to-local-bundle "bsdiff" "os-core-update"
mixer-bundle-add "os-core-update"
mixer-build-bundles > $LOGDIR/build_bundles_20.log
mixer-build-update > $LOGDIR/build_update_20.log
}
@test "Create version 30 with an upstream bundle deleted" {
mixer-versions-update 30
mixer-bundle-remove "editors"
mixer-build-bundles > $LOGDIR/build_bundles_30.log
mixer-build-update > $LOGDIR/build_update_30.log
}
# vi: ft=sh ts=8 sw=2 sts=2 et tw=80
@@ -1,4 +0,0 @@
03-create-mix-with-unique-bundle
================================
This test creates an initial version 10, a version 20 with a unique bundle
that does not exist in Clear, and contains a package that is not in Clear.
@@ -1,4 +0,0 @@
04-add-unique-package-to-clear-bundle
=====================================
This test creates an initial version 10, a version 20 with a unique package
that does not exist in Clear, and is added to an existing Clear bundle.
@@ -0,0 +1,5 @@
04-create-mix-with-custom-content
=================================
This test creates a mix version 10 with a unique bundle that does not exist
upstream and contains a package that is not in upstream. All upstream bundles
have been stripped down for efficiency and are thus edited local copies.
+24
View File
@@ -0,0 +1,24 @@
#!/usr/bin/env bats
# shared test functions
load ../../lib/mixerlib
setup() {
global_setup
}
@test "Create stripped down mix 10 with custom content in custom bundle" {
mixer-init-stripped-down $CLRVER 10
localize_builder_conf
download-rpm "http://rpmfind.net/linux/fedora/linux/development/rawhide/Everything/x86_64/os/Packages/j/json-c-0.13.1-1.fc29.i686.rpm"
mixer-add-rpms
create-empty-local-bundle "testbundle"
add-package-to-local-bundle "json-c" "testbundle"
mixer-bundle-add "testbundle"
mixer-build-bundles > $LOGDIR/build_bundles.log
mixer-build-update > $LOGDIR/build_update.log
}
# vi: ft=sh ts=8 sw=2 sts=2 et tw=80
@@ -0,0 +1,6 @@
05-create-mix-with-blended-content
==================================
This test creates a mix version 10 with two blended bundles: an upstream bundle
with a unique package that does not exist upstream added, and a custom bundle
with a package from upstream added. All upstream bundles have been stripped down
for efficiency and are thus edited local copies.
+33
View File
@@ -0,0 +1,33 @@
#!/usr/bin/env bats
# shared test functions
load ../../lib/mixerlib
setup() {
global_setup
}
@test "Create stripped down mix 10 with blended bundles" {
mixer-init-stripped-down $CLRVER 10
localize_builder_conf
download-rpm "http://rpmfind.net/linux/fedora/linux/development/rawhide/Everything/x86_64/os/Packages/j/json-c-0.13.1-1.fc29.i686.rpm"
mixer-add-rpms
# Put custom content in upstream bundle
create-empty-local-bundle "os-core-update"
add-package-to-local-bundle "bsdiff" "os-core-update"
add-package-to-local-bundle "json-c" "os-core-update"
mixer-bundle-add "os-core-update"
# Put upstream content in custom bundle
create-empty-local-bundle "testbundle"
add-package-to-local-bundle "json-c" "testbundle"
add-package-to-local-bundle "bsdiff" "testbundle"
mixer-bundle-add "testbundle"
mixer-build-bundles > $LOGDIR/build_bundles.log
mixer-build-update > $LOGDIR/build_update.log
}
# vi: ft=sh ts=8 sw=2 sts=2 et tw=80
@@ -1,4 +0,0 @@
05-remove-package-from-clear-bundle
===================================
This test creates a version 10, then version 20 with the Clear editors bundle
added, and a version 30 with emacs removed from the editors bundle definition.
@@ -1,33 +0,0 @@
#!/usr/bin/env bats
# shared test functions
load ../../lib/mixerlib
setup() {
setup_builder_conf
}
@test "Create initial mix 10" {
mixer-init-versions $CLRVER 10
clean-bundle-dir
mixer-build-bundles
mixer-create-update
}
@test "Create version 20 with Clear editors bundle added" {
mixer-init-versions $CLRVER 20
add-bundle "editors"
add-package "joe" "editors"
add-package "nano" "editors"
mixer-build-bundles
mixer-create-update > $BATS_TEST_DIRNAME/create_update-20.log
}
@test "Create version 30 with nano removed from editors bundle" {
mixer-init-versions $CLRVER 30
remove-package "nano" "editors"
mixer-build-bundles
mixer-create-update > $BATS_TEST_DIRNAME/create_update-30.log
}
# vi: ft=sh ts=8 sw=2 sts=2 et tw=80
@@ -1,9 +0,0 @@
.PHONY: check clean
check:
bats ./run.bats
CLEANDIRS = ./update ./test-chroot ./logs ./.repos ./bundles ./update ./mix-bundles ./clr-bundles ./local-yum ./results ./repodata ./local-rpms ./upstream-bundles ./local-bundles
CLEANFILES = ./*.log ./run.bats.trs ./yum.conf.in ./builder.conf ./.{c,m}* *.pem .yum-mix.conf mixversion upstreamurl upstreamversion mixbundles
clean:
sudo rm -rf $(CLEANDIRS) $(CLEANFILES)
@@ -1,4 +0,0 @@
06-create-mix-with-swapped-clear-packages
===================================
This test creates a version 10, then version 20 with a package swapped between
os-core and os-core-update.
@@ -1,28 +0,0 @@
#!/usr/bin/env bats
# shared test functions
load ../../lib/mixerlib
setup() {
setup_builder_conf
}
@test "Create initial mix 10" {
mixer-init-versions $CLRVER 10
clean-bundle-dir
add-bundle "os-core-update"
add-package "swupd-client" "os-core-update"
add-package "bsdiff" "os-core-update"
mixer-build-bundles
mixer-create-update
}
@test "Create version 20 with swupd moved from os-core-update into os-core" {
mixer-init-versions $CLRVER 20
remove-package "swupd-client" "os-core-update"
add-package "swupd-client" "os-core"
mixer-build-bundles
mixer-create-update > $BATS_TEST_DIRNAME/create_update-20.log
}
# vi: ft=sh ts=8 sw=2 sts=2 et tw=80
+14
View File
@@ -0,0 +1,14 @@
#!/usr/bin/env bats
# shared test functions
#load ../../lib/mixerlib
#setup() {
# global_setup
#}
# TODO: fill out once auto format bump implemented
#@test "Create initial mix 10" {
#}
# vi: ft=sh ts=8 sw=2 sts=2 et tw=80
@@ -1,9 +0,0 @@
.PHONY: check clean
check:
bats ./run.bats
CLEANDIRS = ./update ./test-chroot ./logs ./.repos ./bundles ./update ./mix-bundles ./clr-bundles ./local-yum ./results ./repodata ./local-rpms ./upstream-bundles ./local-bundles
CLEANFILES = ./*.log ./run.bats.trs ./yum.conf.in ./builder.conf ./.{c,m}* *.pem .yum-mix.conf mixversion upstreamurl upstreamversion mixbundles
clean:
sudo rm -rf $(CLEANDIRS) $(CLEANFILES)
@@ -1,4 +0,0 @@
07-add-clear-package-to-custom-bundle
====================================
This test creates a version 10, then version 20 with a Clear package added to
a custom bundle not included in upstream Clear.
@@ -1,29 +0,0 @@
#!/usr/bin/env bats
# shared test functions
load ../../lib/mixerlib
setup() {
setup_builder_conf
}
@test "Create initial mix 10" {
mixer-init-versions $CLRVER 10
clean-bundle-dir
add-bundle "os-core-update"
add-package "bsdiff" "os-core-update"
add-package "swupd-client" "os-core-update"
mixer-build-bundles
mixer-create-update
}
@test "Create version 20 with swupd moved from os-core-update into custom testbundle" {
mixer-init-versions $CLRVER 20
remove-package "swupd-client" "os-core-update"
add-bundle "testbundle"
add-package "swupd-client" "testbundle"
mixer-build-bundles
mixer-create-update > $BATS_TEST_DIRNAME/create_update-20.log
}
# vi: ft=sh ts=8 sw=2 sts=2 et tw=80
-9
View File
@@ -1,9 +0,0 @@
.PHONY: check clean
check:
bats ./run.bats
CLEANDIRS = ./update ./test-chroot ./logs ./.repos ./bundles ./update ./mix-bundles ./clr-bundles ./local-yum ./results ./repodata ./local-rpms ./upstream-bundles ./local-bundles
CLEANFILES = ./*.log ./run.bats.trs ./yum.conf.in ./builder.conf ./.{c,m}* *.pem .yum-mix.conf mixversion upstreamurl upstreamversion mixbundles
clean:
sudo rm -rf $(CLEANDIRS) $(CLEANFILES)
-9
View File
@@ -1,9 +0,0 @@
#!/usr/bin/env bats
# shared test functions
load ../../lib/mixerlib
@test "Create initial mix 10" {
}
# vi: ft=sh ts=8 sw=2 sts=2 et tw=80