Files
seaweedfs/seaweed-block/cmd/blockvolume/volume_lock_env_test.go
T
pingqiuandClaude Opus 5.5 badc7f9596 test: start test-lock-dir children without INVOCATION_ID
A test runner that is itself a systemd service (the CI runner unit) passes
its INVOCATION_ID to every child, and blockvolume rightly refuses
--volume-lock-dir-test-only under systemd. Every subprocess start that
passes the flag now builds the child's environment without INVOCATION_ID
(one helper per test package). The product rule is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 11:23:55 -08:00

38 lines
923 B
Go

package main
import (
"os"
"os/exec"
"strings"
)
// stripSystemdForTestLockDir gives a blockvolume child started with
// --volume-lock-dir-test-only an environment without INVOCATION_ID.
// blockvolume refuses the test override under systemd; a test runner that is
// itself a systemd service (a CI runner unit) would otherwise pass its
// INVOCATION_ID to every child. Other children are left as they are.
func stripSystemdForTestLockDir(cmd *exec.Cmd) *exec.Cmd {
hasFlag := false
for _, a := range cmd.Args[1:] {
if a == "--"+volumeLockDirTestOnlyFlag || strings.HasPrefix(a, "--"+volumeLockDirTestOnlyFlag+"=") {
hasFlag = true
break
}
}
if !hasFlag {
return cmd
}
env := cmd.Env
if env == nil {
env = os.Environ()
}
kept := make([]string, 0, len(env))
for _, kv := range env {
if !strings.HasPrefix(kv, "INVOCATION_ID=") {
kept = append(kept, kv)
}
}
cmd.Env = kept
return cmd
}