Skip to content

Commit

Permalink
reformat powershell scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
nzbr committed Nov 10, 2022
1 parent 101423b commit d75cc32
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 53 deletions.
15 changes: 15 additions & 0 deletions tests/basic-functionality.spec.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
. $PSScriptRoot/lib/lib.ps1

$id = WSL-Install

try {
WSL-Launch $id "nixos-version"
if ($LASTEXITCODE -ne 0) {
throw "Failed to run nixos-version inside the container"
}

# TODO: WSL-Shutdown
}
finally {
WSL-Uninstall($id)
}
18 changes: 9 additions & 9 deletions tests/exit-codes.spec.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
$id = WSL-Install

try {
WSL-Launch $id "true"
if ($LASTEXITCODE -ne 0) {
throw "Command that should succeed failed"
}
WSL-Launch $id "true"
if ($LASTEXITCODE -ne 0) {
throw "Command that should succeed failed"
}

WSL-Launch $id "false"
if ($LASTEXITCODE -eq 0) {
throw "Command that should fail succeeded"
}
WSL-Launch $id "false"
if ($LASTEXITCODE -eq 0) {
throw "Command that should fail succeeded"
}
}
finally {
WSL-Uninstall($id)
WSL-Uninstall($id)
}

15 changes: 0 additions & 15 deletions tests/installer.spec.ps1

This file was deleted.

7 changes: 4 additions & 3 deletions tests/lib/lib.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
if ($IsWindows) {
. $PSScriptRoot/lib_windows.ps1
} else {
. $PSScriptRoot/lib_linux.ps1
. $PSScriptRoot/lib_windows.ps1
}
else {
. $PSScriptRoot/lib_linux.ps1
}
52 changes: 26 additions & 26 deletions tests/lib/lib_linux.ps1
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
function WSL-Install() {
$id = [guid]::NewGuid().ToString()
$id = [guid]::NewGuid().ToString()

# Build docker image from the provided tarball
$tmpdir = $(mktemp -d)
Copy-Item $PSScriptRoot/Dockerfile $tmpdir
Copy-Item nixos-wsl-installer.tar.gz $tmpdir
docker build -t nixos-wsl:$id $tmpdir | Write-Host
Remove-Item $tmpdir -Recurse -Force
# Build docker image from the provided tarball
$tmpdir = $(mktemp -d)
Copy-Item $PSScriptRoot/Dockerfile $tmpdir
Copy-Item nixos-wsl-installer.tar.gz $tmpdir
docker build -t nixos-wsl:$id $tmpdir | Write-Host
Remove-Item $tmpdir -Recurse -Force

# Spawn a new docker container
docker run -di --privileged --init --name $id nixos-wsl:$id /bin/sh | Out-Null
if ($LASTEXITCODE -ne 0) {
throw "Failed to launch container"
}
# Spawn a new docker container
docker run -di --privileged --init --name $id nixos-wsl:$id /bin/sh | Out-Null
if ($LASTEXITCODE -ne 0) {
throw "Failed to launch container"
}

return $id
return $id
}

function WSL-Launch([string]$id, [string]$command) {
docker exec -t $id /nix/nixos-wsl/entrypoint -c "$command"
docker exec -t $id /nix/nixos-wsl/entrypoint -c "$command"
}

# TODO: WSL-CopyFile

function WSL-Shutdown([string]$id) {
docker stop $id
if ($LASTEXITCODE -ne 0) {
throw "Failed to stop container"
}
docker stop $id
if ($LASTEXITCODE -ne 0) {
throw "Failed to stop container"
}
}

function WSL-Uninstall([string]$id) {
docker rm -f $id
if ($LASTEXITCODE -ne 0) {
throw "Failed to remove container"
}
docker rmi nixos-wsl:$id
if ($LASTEXITCODE -ne 0) {
throw "Failed to remove image"
}
docker rm -f $id
if ($LASTEXITCODE -ne 0) {
throw "Failed to remove container"
}
docker rmi nixos-wsl:$id
if ($LASTEXITCODE -ne 0) {
throw "Failed to remove image"
}
}

0 comments on commit d75cc32

Please sign in to comment.