diff options
| author | nzbr <mail@nzbr.de> | 2023-09-29 23:25:53 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-29 23:25:53 +0200 |
| commit | 8735bdfa5fdfa6e90d944ff9f5f806668b53eacb (patch) | |
| tree | 64148d00bbc6f8e1d7ba099cfbf31123113db2f8 /tests | |
| parent | e7d93d0f478b6fbb47c00d03449dc3d08b90abb7 (diff) | |
| parent | ff1413aa34c525bf01145b40b99acfb7868ab285 (diff) | |
Merge pull request #295 from nix-community/prep-release
New release preparation
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/README.md | 10 | ||||
| -rw-r--r-- | tests/basic-functionality.Tests.ps1 | 4 | ||||
| -rw-r--r-- | tests/docker/docker-native.nix | 16 | ||||
| -rw-r--r-- | tests/docker/docker.Tests.ps1 | 1 | ||||
| -rw-r--r-- | tests/lib/Dockerfile | 2 | ||||
| -rw-r--r-- | tests/lib/lib.ps1 | 21 | ||||
| -rw-r--r-- | tests/login-shell/session-variables.nix | 6 | ||||
| -rw-r--r-- | tests/shells.Tests.ps1 | 9 | ||||
| -rw-r--r-- | tests/username-change/username-change.nix | 8 |
9 files changed, 43 insertions, 34 deletions
diff --git a/tests/README.md b/tests/README.md index d285809..7c5eb92 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,7 +1,7 @@ # Tests -This directory contains tests that are executed against a built installer tarball. -The test are written using the [Pester](https://pester.dev/) testing framework +This directory contains tests that are executed against a built NixOS-WSL "legacy" tarball. +The tests are written using the [Pester](https://pester.dev/) testing framework. ## Execute Tests @@ -19,7 +19,9 @@ Running the tests requires Docker and PowerShell to be installed on your system. ### Running the Tests If you haven't already, [install Pester](https://pester.dev/docs/introduction/installation/). -The tests require a `nixos-wsl-installer.tar.gz` to be present in the current working directory or in `./result/tarball`. Refer to the top-level readme on how to build it. +The tests require a "legacy" `nixos-wsl.tar.gz` to be present in the current working directory, which can be built with +`sudo nix run .#nixosConfigurations.legacy.config.system.build.tarballBuilder -- nixos-wsl.tar.gz`. + Once everything is in place, run the test by running the following in PowerShell at the root of this repo: ```powershell @@ -44,6 +46,6 @@ BeforeAll { - A Distro object has the following methods: - `Launch($command)`: Runs the specified command inside the container. Returns the command output - `GetPath($path)`: Returns the path inside the container, that points to the specified file on the host. - - `InstallConfig($path)`: Installs a nix-file as the systems `configuration.nix`. The default configuration is moved to `base.nix`, so that it can be imported by the new config + - `InstallConfig($path)`: Installs a nix-file as the systems `configuration.nix`. - `Shutdown()`: End all processes running in the container - `Uninstall()`: Stop and then delete the container from the system. This should be called in an AfterEach or AfterAll block, so that the test does not leave it on the system. diff --git a/tests/basic-functionality.Tests.ps1 b/tests/basic-functionality.Tests.ps1 index d62823b..9459b15 100644 --- a/tests/basic-functionality.Tests.ps1 +++ b/tests/basic-functionality.Tests.ps1 @@ -7,7 +7,7 @@ Describe "Basic Functionality" { $distro = Install-Distro } - It "is possible to run a command through the installer" { + It "is possible to run a command in the container" { $distro.Launch("nixos-version") $LASTEXITCODE | Should -Be 0 } @@ -34,7 +34,7 @@ Describe "Basic Functionality" { } It "is possible to run a command through nix run" { - $distro.Launch("nix run nixpkgs#neofetch") + $distro.Launch("nix --extra-experimental-features 'nix-command flakes' run nixpkgs#neofetch") $LASTEXITCODE | Should -Be 0 } diff --git a/tests/docker/docker-native.nix b/tests/docker/docker-native.nix index 47ccb7f..f119482 100644 --- a/tests/docker/docker-native.nix +++ b/tests/docker/docker-native.nix @@ -1,12 +1,14 @@ -{ pkgs, lib, ... }: { - imports = [ ./base.nix ]; + imports = [ + <nixos-wsl/modules> + ]; - wsl.docker-native.enable = true; - wsl.docker-native.addToDockerGroup = true; + wsl.enable = true; + users.users.nixos.extraGroups = [ "docker" ]; - # Github Actions runners try to use aufs and fail if this is not set explicitly - virtualisation.docker.daemon.settings = { - "storage-driver" = "vfs"; + virtualisation.docker = { + enable = true; + # Github Actions runners try to use aufs and fail if this is not set explicitly + daemon.settings."storage-driver" = "vfs"; }; } diff --git a/tests/docker/docker.Tests.ps1 b/tests/docker/docker.Tests.ps1 index fefff07..9ea46aa 100644 --- a/tests/docker/docker.Tests.ps1 +++ b/tests/docker/docker.Tests.ps1 @@ -27,7 +27,6 @@ Describe "Docker (native)" { It "should be possible to connect to the internet from a container" { $distro.Launch("docker run --rm -it alpine wget -qO- http://www.msftconnecttest.com/connecttest.txt") | Select-Object -Last 1 | Should -BeExactly "Microsoft Connect Test" - # docker exec -it $distro.id /nix/nixos-wsl/entrypoint -c "docker run --rm -it alpine wget -qO- http://www.msftconnecttest.com/connecttest.txt" | Select-Object -Last 1 | Should -BeExactly "Microsoft Connect Test" $LASTEXITCODE | Should -Be 0 } diff --git a/tests/lib/Dockerfile b/tests/lib/Dockerfile index 1fcea66..e703915 100644 --- a/tests/lib/Dockerfile +++ b/tests/lib/Dockerfile @@ -1,2 +1,2 @@ FROM scratch -ADD nixos-wsl-installer.tar.gz / +ADD nixos-wsl.tar.gz / diff --git a/tests/lib/lib.ps1 b/tests/lib/lib.ps1 index 58b1a42..e3985c9 100644 --- a/tests/lib/lib.ps1 +++ b/tests/lib/lib.ps1 @@ -26,12 +26,9 @@ class Distro { [string]FindTarball() { # Check if a fresh tarball exists in result, otherwise try one in the current directory - $tarball = "./result/tarball/nixos-wsl-installer.tar.gz" + $tarball = "./nixos-wsl.tar.gz" if (!(Test-Path $tarball)) { - $tarball = "./nixos-wsl-installer.tar.gz" - if (!(Test-Path $tarball)) { - throw "Could not find the installer tarball! Run nix build first, or place one in the current directory." - } + throw "Could not find the tarball! Run nix build first, or place one in the current directory." } Write-Host "Using tarball: $tarball" return $tarball @@ -40,10 +37,6 @@ class Distro { [void]InstallConfig([string]$path) { Write-Host "Installing config: $path" - # Move config out of the way - $this.Launch("/bin/sh -c 'test -f /etc/nixos/base.nix || sudo mv /etc/nixos/configuration.nix /etc/nixos/base.nix'") - $LASTEXITCODE | Should -Be 0 - # Copy the new config $this.Launch("sudo cp $($this.GetPath($path)) /etc/nixos/configuration.nix") $LASTEXITCODE | Should -Be 0 @@ -75,7 +68,7 @@ class DockerDistro : Distro { $tarball = $this.FindTarball() if (!([DockerDistro]::imageCreated)) { - # Build docker image from the installer tarball + # Build docker image from the tarball $tmpdir = $(mktemp -d) Copy-Item $PSScriptRoot/Dockerfile $tmpdir Copy-Item $tarball $tmpdir @@ -91,12 +84,14 @@ class DockerDistro : Distro { if ($LASTEXITCODE -ne 0) { throw "Failed to launch container" } + + $this.Launch("sudo nix-channel --update") } [Array]Launch([string]$command) { Write-Host "> $command" $result = @() - docker exec -t $this.id /nix/nixos-wsl/entrypoint -c $command | Tee-Object -Variable result | Write-Host + docker exec -t $this.id /bin/syschdemd -c $command | Tee-Object -Variable result | Write-Host return $result | Remove-Escapes } @@ -135,12 +130,14 @@ class WslDistro : Distro { throw "Failed to import distro" } & wsl.exe --list | Should -Contain $this.id + + $this.Launch("sudo nix-channel --update") } [Array]Launch([string]$command) { Write-Host "> $command" $result = @() - & wsl.exe -d $this.id -e /nix/nixos-wsl/entrypoint -c $command | Tee-Object -Variable result | Write-Host + & wsl.exe -d $this.id -e /bin/syschdemd -c $command | Tee-Object -Variable result | Write-Host return $result | Remove-Escapes } diff --git a/tests/login-shell/session-variables.nix b/tests/login-shell/session-variables.nix index d6525ed..6829bbf 100644 --- a/tests/login-shell/session-variables.nix +++ b/tests/login-shell/session-variables.nix @@ -1,13 +1,15 @@ -{ config, pkgs, lib, ... }: +{ pkgs, lib, ... }: let ver = with lib; substring 0 5 version; in { imports = [ - ./base.nix + <nixos-wsl/modules> "${builtins.fetchTarball "https://github.com/nix-community/home-manager/archive/release-${ver}.tar.gz"}/nixos" ]; + wsl.enable = true; + home-manager.users.nixos = { ... }: { home = { stateVersion = ver; diff --git a/tests/shells.Tests.ps1 b/tests/shells.Tests.ps1 index 184014b..6bcc640 100644 --- a/tests/shells.Tests.ps1 +++ b/tests/shells.Tests.ps1 @@ -11,10 +11,15 @@ Describe "Shells" { @" { pkgs, lib, config, options, ... }: with lib; { - imports = [ ./base.nix ]; + imports = [ + <nixos-wsl/modules> + ]; config = mkMerge [ - { users.users.`${config.wsl.defaultUser}.shell = pkgs.$package; } + { + wsl.enable = true; + users.users.nixos.shell = pkgs.$package; + } (optionalAttrs (hasAttrByPath ["programs" "$package" "enable"] options) { programs.$package.enable = true; }) diff --git a/tests/username-change/username-change.nix b/tests/username-change/username-change.nix index 77a2cdd..32d7e1e 100644 --- a/tests/username-change/username-change.nix +++ b/tests/username-change/username-change.nix @@ -1,6 +1,8 @@ -{ pkgs, lib, ... }: { - imports = [ ./base.nix ]; + imports = [ + <nixos-wsl/modules> + ]; - wsl.defaultUser = lib.mkForce "different-name"; + wsl.enable = true; + wsl.defaultUser = "different-name"; } |
