(t *testing.T)
| 359 | } |
| 360 | |
| 361 | func TestRun_WithGatherStats(t *testing.T) { |
| 362 | tmpDir := t.TempDir() |
| 363 | |
| 364 | // Write template |
| 365 | templateFile := filepath.Join(tmpDir, "template.yaml") |
| 366 | err := os.WriteFile(templateFile, []byte(` |
| 367 | apiVersion: templates.gatekeeper.sh/v1 |
| 368 | kind: ConstraintTemplate |
| 369 | metadata: |
| 370 | name: k8srequiredlabels |
| 371 | spec: |
| 372 | crd: |
| 373 | spec: |
| 374 | names: |
| 375 | kind: K8sRequiredLabels |
| 376 | targets: |
| 377 | - target: admission.k8s.gatekeeper.sh |
| 378 | rego: | |
| 379 | package k8srequiredlabels |
| 380 | violation[{"msg": msg}] { |
| 381 | msg := "test" |
| 382 | } |
| 383 | `), 0o600) |
| 384 | if err != nil { |
| 385 | t.Fatalf("failed to write template file: %v", err) |
| 386 | } |
| 387 | |
| 388 | // Write constraint |
| 389 | constraintFile := filepath.Join(tmpDir, "constraint.yaml") |
| 390 | err = os.WriteFile(constraintFile, []byte(` |
| 391 | apiVersion: constraints.gatekeeper.sh/v1beta1 |
| 392 | kind: K8sRequiredLabels |
| 393 | metadata: |
| 394 | name: require-team-label |
| 395 | `), 0o600) |
| 396 | if err != nil { |
| 397 | t.Fatalf("failed to write constraint file: %v", err) |
| 398 | } |
| 399 | |
| 400 | // Write object |
| 401 | objectFile := filepath.Join(tmpDir, "pod.yaml") |
| 402 | err = os.WriteFile(objectFile, []byte(` |
| 403 | apiVersion: v1 |
| 404 | kind: Pod |
| 405 | metadata: |
| 406 | name: test-pod |
| 407 | `), 0o600) |
| 408 | if err != nil { |
| 409 | t.Fatalf("failed to write object file: %v", err) |
| 410 | } |
| 411 | |
| 412 | // Run with GatherStats enabled |
| 413 | results, err := Run(&Opts{ |
| 414 | Filenames: []string{tmpDir}, |
| 415 | Iterations: 2, |
| 416 | Warmup: 0, |
| 417 | Engine: EngineRego, |
| 418 | GatherStats: true, |
nothing calls this directly
no test coverage detected
searching dependent graphs…