tests: add fakedroid as flake app

This commit is contained in:
Tobias Happ 2022-10-28 19:57:03 +02:00
parent 1c88e73c78
commit 0a3b09df75
3 changed files with 51 additions and 27 deletions

View file

@ -19,28 +19,18 @@ jobs:
name: nix-on-droid
signingKey: "${{ secrets.CACHIX_SIGNING_KEY }}"
- name: Build fakedroid script
run: |
nix \
--log-format bar-with-logs \
--option keep-going true \
--show-trace \
build .#fakedroid \
--impure \
--out-link fakedroid
- name: Initialize fakedroid for channel setup
run: ./fakedroid echo INIT
run: nix run --impure .#fakedroid -- echo INIT
- name: Run tests
run: |
./fakedroid mkdir -p .cache/nix-on-droid-self-test
./fakedroid touch .cache/nix-on-droid-self-test/confirmation-granted
./fakedroid nix-on-droid on-device-test
nix run --impure .#fakedroid -- mkdir -p .cache/nix-on-droid-self-test
nix run --impure .#fakedroid -- touch .cache/nix-on-droid-self-test/confirmation-granted
nix run --impure .#fakedroid -- nix-on-droid on-device-test
- name: Push to cachix
if: always() && github.event_name != 'pull_request'
run: ./fakedroid nix-shell -p cachix --run 'nix --extra-experimental-features nix-command path-info --all | cachix push nix-on-droid'
run: nix run --impure .#fakedroid -- nix-shell -p cachix --run 'nix --extra-experimental-features nix-command path-info --all | cachix push nix-on-droid'
fakedroid-flakes:
@ -59,19 +49,9 @@ jobs:
name: nix-on-droid
signingKey: "${{ secrets.CACHIX_SIGNING_KEY }}"
- name: Build fakedroid script
run: |
nix \
--log-format bar-with-logs \
--option keep-going true \
--show-trace \
build .#fakedroid \
--impure \
--out-link fakedroid
- name: Initialize fakedroid for flake setup
run: USE_FLAKE=1 ./fakedroid echo INIT
run: USE_FLAKE=1 nix run --impure .#fakedroid -- echo INIT
- name: Push to cachix
if: always() && github.event_name != 'pull_request'
run: ./fakedroid nix-shell -p cachix --run 'nix --extra-experimental-features nix-command path-info --all | cachix push nix-on-droid'
run: nix run --impure .#fakedroid -- nix-shell -p cachix --run 'nix --extra-experimental-features nix-command path-info --all | cachix push nix-on-droid'

View file

@ -206,6 +206,45 @@ Use `nix-on-droid switch --flake .#device` to build and activate your configurat
Therefore, every evaluation of a flake configuration will be executed with `--impure` flag. (This behaviour will be
dropped as soon as the default setup does not require it anymore.)
## Emulate `nix-on-droid`-like environment with `fakedroid`
For easier debugging and testing, there is a so-called `fakedroid` environment which
emulates the on-device environment including proot as good as possible.
You can enter this emulated environment with
```sh
nix run --impure ".#fakedroid"
```
This will install nix-on-droid with initial channel setup and save the state of
this session in the `.fakedroid` directory in the project directory. To enter this
environment with initial flake setup, set `USE_FLAKE=1` as environment variable.
Channel and flake setups can co-exist in the `.fakedroid` state directory. To
rebuild/re-test the bootstrap process, remove the `.fakedroid` directory.
To only run a command in fakedroid and not enter an interactive shell, just call it
with the command as arguments:
```sh
nix run --impure ".#fakedroid" -- ls -l
```
## Testing
In the [./tests/on-device](./tests/on-device) directory, there is small set
of [bats](https://github.com/bats-core/bats-core) tests that can be executed on the
android device or run in the `fakedroid` environment.
To run the tests (on device or in fakedroid), run
```sh
nix-on-droid on-device-test
```
**Note:** This currently requires a channel setup and should only be executed on
clean installations.
## Tips
* To grant the app access to the storage, use the toggle in the app settings

View file

@ -53,6 +53,11 @@
type = "app";
program = "${self.packages.${system}.nix-on-droid}/bin/nix-on-droid";
};
fakedroid = {
type = "app";
program = toString self.packages.${system}.fakedroid;
};
});
checks = forEachSystem (system: {