tests: add assertions only relevant for the specific test case

This commit is contained in:
Tobias Happ 2021-12-12 17:11:39 +01:00
parent 726f74d9ec
commit 7f983228fe
5 changed files with 24 additions and 12 deletions

View file

@ -4,4 +4,7 @@ load lib
@test 'default config can be switched into' { @test 'default config can be switched into' {
switch_to_default_config switch_to_default_config
assert_command nix-on-droid nix-shell bash vi find
assert_no_command dash xonsh zsh
} }

View file

@ -3,8 +3,7 @@
load lib load lib
@test 'flake + h-m + #134 overlays case work' { @test 'flake + h-m + #134 overlays case work' {
# start from a known baseline # assertions to verify initial state is as expected
switch_to_default_config
assert_command vi assert_command vi
assert_no_command dash zsh assert_no_command dash zsh

View file

@ -3,11 +3,11 @@
load lib load lib
@test 'flake example works' { @test 'flake example works' {
# start from a known baseline # assertions to verify initial state is as expected
switch_to_default_config
assert_command vi assert_command vi
assert_no_command dash unzip assert_no_command unzip
# set up / build / activate the configuration
nix-shell -p gnused --run \ nix-shell -p gnused --run \
"sed \ "sed \
-e s/vim/nano/ \ -e s/vim/nano/ \
@ -39,5 +39,5 @@ load lib
rm -f ~/.config/nix/nix.conf ~/.config/nixpkgs/flake.nix rm -f ~/.config/nix/nix.conf ~/.config/nixpkgs/flake.nix
switch_to_default_config switch_to_default_config
assert_command vi assert_command vi
assert_no_command dash unzip assert_no_command unzip
} }

View file

@ -2,13 +2,17 @@
load lib load lib
teardown() {
rm -f ~/.config/example
}
@test 'using home-manager works' { @test 'using home-manager works' {
# start from a known baseline # assertions to verify initial state is as expected
switch_to_default_config
assert_command vi assert_command vi
assert_no_command dash assert_no_command dash
! [[ -e ~/.config/example ]] [[ ! -e ~/.config/example ]]
# set up / build / activate the configuration
nix-channel --add https://github.com/rycee/home-manager/archive/release-21.11.tar.gz home-manager nix-channel --add https://github.com/rycee/home-manager/archive/release-21.11.tar.gz home-manager
nix-channel --update nix-channel --update
cp "$ON_DEVICE_TESTS_DIR/config-h-m.nix" ~/.config/nixpkgs/nix-on-droid.nix cp "$ON_DEVICE_TESTS_DIR/config-h-m.nix" ~/.config/nixpkgs/nix-on-droid.nix
@ -30,5 +34,11 @@ load lib
[[ "$output" == success ]] [[ "$output" == success ]]
[[ "$status" == 42 ]] [[ "$status" == 42 ]]
# check that reverting works too
switch_to_default_config switch_to_default_config
assert_command vi
assert_no_command unzip
# file will be still present because home-manager needs to be set up to remove old links
[[ -e ~/.config/example ]]
} }

View file

@ -26,6 +26,9 @@ setup() {
# restore to pre-testing generation before the start of each test # restore to pre-testing generation before the start of each test
$DEFAULT_ACTIVATE_SCRIPT $DEFAULT_ACTIVATE_SCRIPT
# build and activate the version of nix-on-droid that is subject to test
switch_to_default_config
} }
assert_command() { assert_command() {
@ -47,7 +50,4 @@ switch_to_default_config() {
cat "$CHANNEL_DIR/modules/environment/login/nix-on-droid.nix.default" \ cat "$CHANNEL_DIR/modules/environment/login/nix-on-droid.nix.default" \
> ~/.config/nixpkgs/nix-on-droid.nix > ~/.config/nixpkgs/nix-on-droid.nix
nix-on-droid switch nix-on-droid switch
assert_command nix-on-droid nix-shell bash vi find
assert_no_command dash xonsh zsh
} }