36b3af2e3d
PR Check / Code Quality: Format (push) Failing after 1s
PR Check / Code Quality: Lint (darwin) (push) Failing after 0s
PR Check / Code Quality: Lint (freebsd) (push) Failing after 1s
PR Check / Code Quality: Lint (windows) (push) Failing after 1s
PR Check / Code Quality: Lint (linux) (push) Failing after 1s
PR Check / Security: Vulnerability Scan (push) Failing after 0s
Update Documentation / update-docs (push) Failing after 2s
PR Check / Code Quality: Vendor (push) Failing after 1s
PR Check / Code Quality: Coverage (push) Failing after 0s
PR Check / Tests: Unit (macos-latest) (push) Has been cancelled
PR Check / Tests: Unit (ubuntu-24.04) (push) Has been cancelled
PR Check / Tests: Unit (ubuntu-24.04-arm) (push) Has been cancelled
PR Check / Tests: Unit (windows-latest) (push) Has been cancelled
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
//go:build windows
|
|
|
|
package proc
|
|
|
|
import (
|
|
"os"
|
|
"reflect"
|
|
"strings"
|
|
"testing"
|
|
"unicode/utf16"
|
|
)
|
|
|
|
func TestParseEnvBlock(t *testing.T) {
|
|
var block []uint16
|
|
for _, e := range []string{"A=1", `PATH=C:\Windows`} {
|
|
block = append(block, utf16.Encode([]rune(e))...)
|
|
block = append(block, 0)
|
|
}
|
|
block = append(block, 0) // terminating empty entry
|
|
|
|
if envBlockEnd(block) < 0 {
|
|
t.Error("envBlockEnd should find the terminator")
|
|
}
|
|
got := parseEnvBlock(block)
|
|
want := []string{"A=1", `PATH=C:\Windows`}
|
|
if !reflect.DeepEqual(got, want) {
|
|
t.Errorf("parseEnvBlock = %v, want %v", got, want)
|
|
}
|
|
}
|
|
|
|
// TestReadProcessEnvSelf confirms the PEB environment read returns this
|
|
// process's environment (PATH is always set).
|
|
func TestReadProcessEnvSelf(t *testing.T) {
|
|
p, err := ReadProcess(os.Getpid())
|
|
if err != nil {
|
|
t.Fatalf("ReadProcess(self): %v", err)
|
|
}
|
|
if len(p.Env) == 0 {
|
|
t.Fatal("expected a non-empty environment for self")
|
|
}
|
|
for _, e := range p.Env {
|
|
if strings.HasPrefix(strings.ToUpper(e), "PATH=") {
|
|
return
|
|
}
|
|
}
|
|
t.Errorf("PATH not found among %d env entries", len(p.Env))
|
|
}
|