Skip to content

Commit f396aa6

Browse files
integration tests for windows
1 parent dd4a67e commit f396aa6

File tree

13 files changed

+192
-0
lines changed

13 files changed

+192
-0
lines changed

.github/workflows/ci.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ jobs:
5151
- run: "./pplog.exe -v"
5252
- shell: bash # naked `echo` won't work on windows
5353
run: "./pplog.exe -d bash -c 'echo \\{\\\"time\\\":\\\"2024-12-02T12:00:00Z\\\",\\\"level\\\":\\\"INFO\\\",\\\"msg\\\":\\\"Hello\\\"\\}'"
54+
- run: |
55+
.\behavioral-tests\windows-tests\run.ps1
56+
shell: pwsh
5457
test:
5558
runs-on: ubuntu-latest
5659
timeout-minutes: 10

behavioral-tests/run.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ for cs in $(find . -mindepth 1 -maxdepth 1 -type d | sort)
1515
do
1616
(
1717
cd $cs
18+
if test ! -e expected.log
19+
then
20+
echo "SKIP: $cs"
21+
exit 0
22+
fi
1823
if test -x ./custom-run.sh
1924
then
2025
./custom-run.sh
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Write-Output "Arguments: $args"
2+
3+
$sendCtrlBreakScriptPath = Join-Path -Path $PSScriptRoot -ChildPath "custom-send-break.ps1"
4+
$proc = Start-Process -FilePath "powershell.exe" -ArgumentList "-File `"$sendCtrlBreakScriptPath`"" -PassThru -NoNewWindow
5+
6+
try {
7+
while ($true) {
8+
Start-Sleep -Seconds 5
9+
}
10+
} finally {
11+
# windows does not allow to write into pipe after interruption (Write-Output)
12+
# we can only write to console directly
13+
Write-Host "Getting SIGNAL SIGINT. Exiting"
14+
}
15+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
try {
2+
go run ..\..\..\cmd\... powershell .\custom-fake-server.ps1 ARG1 ARG2 |
3+
Tee-Object -FilePath output.log
4+
} finally {
5+
# there is windows limitation: Write-Output (write to pipe)
6+
# does not write anything after interruption.
7+
# we can write directly to console using Write-Host,
8+
# but Tee-Object does not receive this record too.
9+
# the only way to get record in output log file is
10+
# to write it manually:
11+
# $msg = 'some graceful shutdown logs..."'
12+
# $msg | Out-File -FilePath "output.log" -Append
13+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Add-Type @"
2+
using System;
3+
using System.Runtime.InteropServices;
4+
5+
public class NativeMethods {
6+
[DllImport("kernel32.dll", SetLastError = true)]
7+
public static extern bool GenerateConsoleCtrlEvent(uint dwCtrlEvent, uint dwProcessGroupId);
8+
9+
[DllImport("kernel32.dll", SetLastError = true)]
10+
public static extern bool FreeConsole();
11+
12+
public const uint CTRL_C_EVENT = 0;
13+
public const uint CTRL_BREAK_EVENT = 1;
14+
}
15+
"@
16+
17+
function Send-CtrlBreakEvent {
18+
param (
19+
[int]$parentPid
20+
)
21+
22+
[NativeMethods]::GenerateConsoleCtrlEvent([NativeMethods]::CTRL_C_EVENT, 0)
23+
[NativeMethods]::FreeConsole()
24+
}
25+
26+
Write-Output 'Sleeping...'
27+
Start-Sleep -Seconds 1
28+
Write-Output 'Going to kill parent process...'
29+
30+
$parentPid = (Get-WmiObject Win32_Process -Filter "ProcessId=$PID").ParentProcessId
31+
$null = Send-CtrlBreakEvent -parentPid $parentPid
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
INVALID JSON: "Arguments: ARG1 ARG2\r"
2+
INVALID JSON: "Sleeping...\r"
3+
INVALID JSON: "Going to kill parent process...\r"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
12:00:00 INFO OK source.file=/Users/slog/main.go source.function=main.main source.line=14 user=1
2+
NOJSON: Broken raw error message
3+
12:05:00 INFO OK source.file=/Users/slog/main.go source.function=main.main source.line=14 user=2
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# PPLog config
2+
#
3+
# GitHub: https://github.com/michurin/human-readable-json-logging
4+
# Install: go install -v github.com/michurin/human-readable-json-logging/cmd/...@latest
5+
#
6+
# Configuration file syntax: systemd env-files https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html#EnvironmentFile=
7+
#
8+
# Configuration variables:
9+
# - PPLOG_LOGLINE for JSON-lines
10+
# - PPLOG_ERRLINE for non-JSON-lines
11+
#
12+
# Templates: go standard test/template: https://pkg.go.dev/text/template
13+
#
14+
# Colors: terminal standard color sequences. `\e` considering as '\033' (escape)
15+
#
16+
# Color hints:
17+
#
18+
# Text colors Text High Background Hi Background Decoration
19+
# ------------------ ------------------ ------------------ ------------------- --------------------
20+
# \e[30mBlack \e[0m \e[90mBlack \e[0m \e[40mBlack \e[0m \e[100mBlack \e[0m \e[1mBold \e[0m
21+
# \e[31mRed \e[0m \e[91mRed \e[0m \e[41mRed \e[0m \e[101mRed \e[0m \e[4mUnderline \e[0m
22+
# \e[32mGreen \e[0m \e[92mGreen \e[0m \e[42mGreen \e[0m \e[102mGreen \e[0m \e[7mReverse \e[0m
23+
# \e[33mYellow \e[0m \e[93mYellow \e[0m \e[43mYellow \e[0m \e[103mYellow \e[0m
24+
# \e[34mBlue \e[0m \e[94mBlue \e[0m \e[44mBlue \e[0m \e[104mBlue \e[0m Combinations
25+
# \e[35mMagenta\e[0m \e[95mMagenta\e[0m \e[45mMagenta\e[0m \e[105mMagenta\e[0m -----------------------
26+
# \e[36mCyan \e[0m \e[96mCyan \e[0m \e[46mCyan \e[0m \e[106mCyan \e[0m \e[1;4;103;31mWARN\e[0m
27+
# \e[37mWhite \e[0m \e[97mWhite \e[0m \e[47mWhite \e[0m \e[107mWhite \e[0m
28+
29+
PPLOG_LOGLINE='
30+
{{- if .time }}{{ .time | tmf "2006-01-02T15:04:05Z07:00" "15:04:05" }}{{ end }}
31+
{{- if .level }} {{ if eq .level "INFO" }}\e[32m{{ end }}{{ if eq .level "ERROR" }}\e[91m{{ end }}{{ .level }}\e[0m{{ end }}
32+
{{- if .msg }} \e[97m{{ .msg }}\e[0m{{ end }}
33+
{{- range .ALL | rm "time" "level" "msg" }} \e[33m{{ .K }}\e[0m={{ .V }}{{ end }}
34+
'
35+
36+
PPLOG_ERRLINE='\e[7mNOJSON:\e[0m \e[97m{{ .TEXT | trimSpace }}\e[0m'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2024-12-02T12:00:00-05:00 [INFO] OK source.file=/Users/slog/main.go source.function=main.main source.line=14 user=1
2+
INVALID JSON: "Broken raw error message\r"
3+
2024-12-02T12:05:00-05:00 [INFO] OK source.file=/Users/slog/main.go source.function=main.main source.line=14 user=2
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Write-Output '{"time":"2024-12-02T12:00:00-05:00","level":"INFO","source":{"function":"main.main","file":"/Users/slog/main.go","line":14},"msg":"OK","user":1}'
2+
Write-Output 'Broken raw error message'
3+
Write-Output '{"time":"2024-12-02T12:05:00-05:00","level":"INFO","source":{"function":"main.main","file":"/Users/slog/main.go","line":14},"msg":"OK","user":2}'

0 commit comments

Comments
 (0)