Skip to content

Commit 7bdb99b

Browse files
test(e2e): restore Windows agent-profile helpers on list/describe PR
Move writeProcessesDYamlContent and process-owner helpers here where the agent-profile E2E tests use them, after dropping them from spawn-profiles.
1 parent 8014739 commit 7bdb99b

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/new-e2e/tests/agent-runtimes/procmgr/procmgr_win_helpers_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package procmgr
77

88
import (
9+
"encoding/base64"
910
"fmt"
1011
"strings"
1112
"testing"
@@ -57,6 +58,16 @@ func ensureWindowsDirPS(dir string) string {
5758
return psRemote(`New-Item -ItemType Directory -Force -Path '%s' | Out-Null`, dir)
5859
}
5960

61+
// writeProcessesDYamlContent writes a processes.d YAML file as UTF-8 without a BOM.
62+
// Set-Content -Encoding utf8 adds a BOM on Windows PowerShell 5.1, which breaks dd-procmgr parsing.
63+
func writeProcessesDYamlContent(yamlPath, content string) string {
64+
b64 := base64.StdEncoding.EncodeToString([]byte(content))
65+
return psRemote(
66+
`$ErrorActionPreference='Stop'; $p='%s'; $b = [Convert]::FromBase64String('%s'); [IO.File]::WriteAllBytes($p, $b)`,
67+
yamlPath, b64,
68+
)
69+
}
70+
6071
// replaceProcessesDYaml applies old→new in processes.d YAML without a UTF-8 BOM.
6172
// Set-Content -Encoding utf8 adds a BOM on Windows PowerShell 5.1, which breaks dd-procmgr parsing.
6273
func replaceProcessesDYaml(yamlPath, old, new string) string {
@@ -66,6 +77,24 @@ func replaceProcessesDYaml(yamlPath, old, new string) string {
6677
)
6778
}
6879

80+
func windowsProcessOwnerByName(host *e2ecomponents.RemoteHost, name string) (string, error) {
81+
script := psRemote(
82+
`$p = Get-CimInstance Win32_Process -Filter "Name='%s'" | Select-Object -First 1; if ($null -eq $p) { exit 1 }; $o = Invoke-CimMethod -InputObject $p -MethodName GetOwner; if ($o.ReturnValue -ne 0) { exit $o.ReturnValue }; "$($o.Domain)/$($o.User)"`,
83+
name,
84+
)
85+
out, err := host.Execute(script)
86+
return strings.TrimSpace(out), err
87+
}
88+
89+
func windowsProcessOwnerByPID(host *e2ecomponents.RemoteHost, pid string) (string, error) {
90+
script := psRemote(
91+
`$p = Get-CimInstance Win32_Process -Filter "ProcessId=%s"; if ($null -eq $p) { exit 1 }; $o = Invoke-CimMethod -InputObject $p -MethodName GetOwner; if ($o.ReturnValue -ne 0) { exit $o.ReturnValue }; "$($o.Domain)/$($o.User)"`,
92+
pid,
93+
)
94+
out, err := host.Execute(script)
95+
return strings.TrimSpace(out), err
96+
}
97+
6998
func waitProcmgrDescribeRunning(
7099
t *testing.T,
71100
host *e2ecomponents.RemoteHost,

0 commit comments

Comments
 (0)