-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: On-device tests #146
WIP: On-device tests #146
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love it! Thanks a lot, the first step for test automation :) Had some comments, but beware, I did not run/test any of my suggestions, so there may be some typos.
I do not see any big thing missing, but I think at some point we should have a test for every option, but that doesn't need to be a on-device test.
tests/on-device/.run.sh
Outdated
cp -r ~/.config.bak ~/.config | ||
fi | ||
|
||
nix-shell -p bats --run 'bats .' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scripts should depend on the working directory from where they are called.
With dirname "$(readlink -f "$0")"
, you get the directory where your script is, so
# somewhere at the top
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
# then here
nix-shell -p bats --run "bats ${SCRIPT_DIR}"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorporated.
if [[ ! -d ~/.config.bak ]]; then | ||
mv ~/.config ~/.config.bak | ||
cp -r ~/.config.bak ~/.config | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't be backupping the ~/.config/nixpkgs
directory be enough? That would reduce possible unwanted side effects.
out=$(nix-shell -p hello --run hello) | ||
[[ "$out" == 'Hello, world!' ]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit more idiomatic :)
out=$(nix-shell -p hello --run hello) | |
[[ "$out" == 'Hello, world!' ]] | |
run nix-shell -p hello --run hello | |
[[ "$output" == 'Hello, world!' ]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't check the retcode that way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah okay, then maybe be more explicit with what you want to test with [[ $status -eq 0 ]]
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
run also collects stderr into "$output", nah
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to have stdout and stderr separate, then you need --separate-stderr
Additionally, you can use --separate-stderr to split stdout and stderr into $output/$stderr and ${lines[@]}/${stderr_lines[@]}.
https://bats-core.readthedocs.io/en/stable/writing-tests.html#run-test-other-commands
tests/on-device/lib.sh
Outdated
@@ -0,0 +1,18 @@ | |||
switch_to_default_config() { | |||
rm -rf ~/.config/nix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be needed, if you always you the cli args for nix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to follow what we recommend in the README, not what's easier to script. But I'm having second thoughts, yeah
tests/on-device/lib.sh
Outdated
CHANNEL_DIR=$HOME/.cache/nix-on-droid-self-test/channel | ||
cp $CHANNEL_DIR/modules/environment/login/nix-on-droid.nix.default \ | ||
~/.config/nixpkgs/nix-on-droid.nix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CHANNEL_DIR=$HOME/.cache/nix-on-droid-self-test/channel | |
cp $CHANNEL_DIR/modules/environment/login/nix-on-droid.nix.default \ | |
~/.config/nixpkgs/nix-on-droid.nix | |
CHANNEL_DIR=$HOME/.cache/nix-on-droid-self-test/channel | |
cp "$(nix-instantiate --eval --expr "<nix-on-droid/modules/environment/login/nix-on-droid.nix.default>")" \ | |
~/.config/nixpkgs/nix-on-droid.nix |
tests/on-device/config-h-m.nix
Outdated
{ pkgs, lib, ... }: | ||
{ | ||
home.stateVersion = "21.05"; | ||
nixpkgs.overlays = lib.mkIf (lib.hasAttrByPath [ "nixpkgs" "overlays" ] config) config.nixpkgs.overlays; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not enable home-manager.useGlobalPkgs
instead of this monstrosity? I am still not sure if that complexity is really necessary for setting just the overlay :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because that's what we recommend to users
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't be needed for 21.11 anymore
32a2ca9
to
6afab1b
Compare
Not finished yet, will need more time with this. |
tests/on-device/.run.sh
Outdated
cp -r ~/.config.bak ~/.config | ||
fi | ||
|
||
pushd "$SCRIPT_DIR" # for lib.sh import |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can replace the pushd stuff with this nice feature to load shared code: https://bats-core.readthedocs.io/en/stable/writing-tests.html#load-share-common-code
7324bd7
to
f607198
Compare
added config-flake-h-m test, it currently fails with |
Sorry, my phone is really slow today. So can you test for me if the tests would fail with the following changes? diff --git i/tests/on-device/config-flake-h-m.cfg.nix w/tests/on-device/config-flake-h-m.cfg.nix
index 2df66f5..9c0310b 100644
--- i/tests/on-device/config-flake-h-m.cfg.nix
+++ w/tests/on-device/config-flake-h-m.cfg.nix
@@ -8,12 +8,5 @@
# no nixpkgs.overlays defined
environment.packages = with pkgs; [ zsh ];
- home-manager.config =
- { pkgs, ... }:
- {
- home.stateVersion = "21.05";
-
- nixpkgs.overlays = config.nixpkgs.overlays;
- home.packages = with pkgs; [ dash ];
- };
+ nixpkgs.overlays = [];
} Because I am not sure, if the problem is in nix-on-droid's or home-manager's nixpkgs definition.. |
(after also commenting out the now-missing experimentalFeatures) |
That should not print this message for |
I totally messed up the condition of the assertion.. :D I will push it to my PR in a second. |
tests/on-device/.run.sh
Outdated
cp -r ~/.config.bak ~/.config | ||
fi | ||
|
||
bats "${SCRIPT_DIR}" --verbose-run -x -T |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These options throw an error on my phone..
tests/on-device/config-default.bats
Outdated
@@ -0,0 +1,7 @@ | |||
# Copyright (c) 2019-2021, see AUTHORS. Licensed under MIT License, see LICENSE. | |||
|
|||
load lib.sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to write load lib
and rename lib.sh
to lib.bash
The tests just seem to hang when I run them.. Only the lines
|
Yeah, flake ones take a lot of time to run... I'm actually working on an environment to debug them on PC, hope this makes sense in the end. |
So my testing branch (based of latest release-21.11 (#147) + cherry-picked commits from this PR + 7a1f8eb) runs perfectly fine :) So if you incorporate 7a1f8eb into this PR, from my point of view, #147 and this PR can be merged :) |
Awesome! Now I just must somehow contain the testing scope creep... |
Oh boy, that script looks complicated :D |
While using your tests for my flake PR just as a quick heads up before I lose the thought: If you are changing nix-on-droid script itself you need to do a manual switch and run the test and do manual rollbacks in case of failures. Maybe (not necessarily in this PR) we find a good solution for improving UX for that case :) |
f607198
to
8510c23
Compare
I've decided to quick-and-dirty automate a few things I often check manually on PRs and releases inside a disposable installation.
@Gerschtli thoughts? Other high-profile scenarios I'm missing?