mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-01 04:21:29 +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:
2
Makefile
2
Makefile
@@ -33,5 +33,7 @@ test-unit:
|
||||
|
||||
# Privileged suite: runs the `privileged`-tagged tests inside a --privileged
|
||||
# --cap-add=NET_ADMIN container via the ory/dockertest harness. Requires Docker.
|
||||
# Narrow the run with env vars, e.g.:
|
||||
# PRIV_RUN=TestNftablesManager PRIV_PKGS=./client/firewall/nftables/... make test-privileged
|
||||
test-privileged:
|
||||
@go test -tags 'devcert privileged' -timeout 30m -run TestRunPrivilegedSuiteInDocker -v ./client/testutil/privileged/...
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -19,8 +19,14 @@ go test -tags devcert ./...
|
||||
# Privileged suite: runs the privileged-tagged tests inside a
|
||||
# --privileged --cap-add=NET_ADMIN container (requires Docker).
|
||||
make test-privileged
|
||||
|
||||
# Narrow the container run to a single test / package:
|
||||
PRIV_RUN=TestNftablesManager PRIV_PKGS=./client/firewall/nftables/... make test-privileged
|
||||
```
|
||||
|
||||
`PRIV_RUN` adds a `-run` test-name filter and `PRIV_PKGS` overrides the package
|
||||
list; both are optional and default to the full privileged suite.
|
||||
|
||||
`make test-privileged` invokes the `ory/dockertest` harness in
|
||||
`client/testutil/privileged/`. The harness:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user