mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-05 04:59:06 +02:00
[client] add PRIV_RUN/PRIV_PKGS filters to the privileged test harness
The dockertest harness now reads two optional env vars when building the in-container `go test` command: PRIV_RUN adds a -run test-name filter and PRIV_PKGS overrides the package list. Both empty reproduce the full privileged suite, so CI and `make test-privileged` behave as before. Lets a developer run a single privileged test in the container, e.g.: PRIV_RUN=TestNftablesManager PRIV_PKGS=./client/firewall/nftables/... make test-privileged
This commit is contained in:
@@ -99,12 +99,7 @@ func TestRunPrivilegedSuiteInDocker(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute)
|
||||
defer cancel()
|
||||
|
||||
script := fmt.Sprintf(
|
||||
"apk update >/dev/null && apk add --no-cache %s >/dev/null && %s | xargs go test -buildvcs=false -tags 'devcert privileged' -v -timeout 20m -p 1",
|
||||
alpinePackages, privilegedTestPackages,
|
||||
)
|
||||
|
||||
result, err := resource.Exec(ctx, []string{"sh", "-c", script})
|
||||
result, err := resource.Exec(ctx, []string{"sh", "-c", buildTestScript()})
|
||||
if err != nil {
|
||||
t.Fatalf("run privileged suite in container: %v", err)
|
||||
}
|
||||
@@ -153,3 +148,23 @@ func goEnv(t *testing.T, key string) string {
|
||||
}
|
||||
return strings.TrimSpace(out.String())
|
||||
}
|
||||
|
||||
// buildTestScript builds the in-container command. PRIV_PKGS overrides the package
|
||||
// list (default: the full filtered set); PRIV_RUN adds a -run test-name filter.
|
||||
// Both empty reproduces the full privileged suite.
|
||||
func buildTestScript() string {
|
||||
pkgs := privilegedTestPackages + " | xargs"
|
||||
if p := os.Getenv("PRIV_PKGS"); p != "" {
|
||||
pkgs = "echo " + p + " | xargs"
|
||||
}
|
||||
|
||||
runFilter := ""
|
||||
if r := os.Getenv("PRIV_RUN"); r != "" {
|
||||
runFilter = "-run '" + r + "' "
|
||||
}
|
||||
|
||||
return fmt.Sprintf(
|
||||
"apk update >/dev/null && apk add --no-cache %s >/dev/null && %s go test -buildvcs=false -tags 'devcert privileged' %s-v -timeout 20m -p 1",
|
||||
alpinePackages, pkgs, runFilter,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user