nginx/kubernetes-ingress/nic-testing

Claude Code and agent skill by nginx/kubernetes-ingress

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Testing patterns for NIC including Go table-driven tests, snapshot tests, and Python integration tests. Use when writing unit tests, snapshot tests, policy tests, template tests, Helm tests, or pytest integration tests for the Ingress Controller.

Install

npx vskill@latest install nginx/kubernetes-ingress/nic-testing

SKILL.md

The same SKILL.md was published earlier as nginx/kubernetes-ingress/nic-testing.

NIC Testing Patterns

Build and Test Commands

CommandPurpose
make testRun all Go tests (-tags=helmunit -shuffle=on ./...)
make test-update-snapsRegenerate snapshot golden files (UPDATE_SNAPS=always)
make lintgolangci-lint via Docker, diff against origin/main
make formatgoimports + gofumpt
make coverGenerate test coverage report
make lint-pythonPython test formatting: isort + black

Always use make test over raw go test. Run make test-update-snaps when template output changes.

Note: Helm tests use the //go:build helmunit build tag -- they are only compiled and run when -tags=helmunit is passed (included in make test).


Snapshot Tests -- MANDATORY workflow

This is the single most frequently missed step. Treat it as a hard gate, not an optional cleanup.

The three snapshot packages
PackageGolden filesCovers
internal/configs/version1internal/configs/version1/__snapshots__/Ingress templates (nginx.tmpl, nginx.ingress.tmpl, and Plus variants)
internal/configs/version2internal/configs/version2/__snapshots__/VirtualServer / VSR / TransportServer templates (OSS + Plus)
charts/testscharts/tests/__snapshots__/Rendered Helm manifests (terratest, helmunit build tag)
Trigger table -- if you touched this, snapshots are in scope
ChangeSnapshot action required
Any *.tmpl fileRegenerate and add a case that exercises the new directive
Template struct field (version1/config.go, version2/http.go, version2/stream.go)Add the field to the fixture used by the snapshot test, then regenerate
Config generation (internal/configs/*.go) that changes rendered outputRegenerate; confirm the diff matches the intended output
charts/nginx-ingress/templates/**, values.yaml, _helpers.tplAdd charts/tests/testdata/<feature>.yaml + a helmunit_test.go case, then regenerate
Deleting or renaming a snapshot testRegenerate -- snaps.Clean prunes the obsolete entry from the golden file
Required sequence
  1. Add or extend a test case first. Regenerating alone only re-records existing fixtures. If no fixture sets your new field, the golden file will never contain your directive and the feature ships untested.
  2. Run make test-update-snaps.
  3. Inspect what actually changed:

``bash git status --short internal/configs/version1/__snapshots__ \ internal/configs/version2/__snapshots__ charts/tests/__snapshots__ git diff -- '**/__snapshots__/**' ``

  1. Read the diff and confirm your directive is present in the golden output for every edition that supports it. An empty diff after a .tmpl change means no fixture exercises the new branch -- go back to step 1.
  2. Run make test to confirm the suite is green against the regenerated files.
  3. Commit the __snapshots__ changes in the same commit as the template change.
Edition parity -- OSS vs Plus

OSS and Plus templates are separate files with separate golden entries, so decide up front which editions the feature targets:

FeatureExpected snapshot diff
Supported by both editionsBoth the OSS and Plus golden files change
Plus-only (health checks, OIDC, WAF, zone_sync, NGINX Plus API)Only the Plus golden file changes -- the directive must never appear in OSS output
OSS-onlyOnly the OSS golden file changes

A one-sided diff is a bug only when the feature is supposed to be shared. Never add a Plus-only directive to an OSS snapshot to "fix" a one-sided diff -- that means the directive leaked into the OSS template and NGINX OSS will fail to start.

Self-check before declaring done
  • [ ] Every .tmpl I edited has at least one snapshot case that renders the new directive.
  • [ ] The golden files changed for exactly the editions the feature supports -- both for shared features, Plus-only for Plus features.
  • [ ] No Plus-only directive appears in an OSS golden file.
  • [ ] git diff on __snapshots__ is non-empty and reviewed line by line.
  • [ ] make test passes without UPDATE_SNAPS.
  • [ ] The regenerated golden files are staged for commit.

Go Unit Tests

Table-Driven Tests (primary pattern)
go
func TestValidateMyPolicy(t *testing.T) {
t.Parallel()
tests := []struct {
policy *v1.Policy
isPlus bool
msg string
}{
{ /* valid case */ },
{ /* edge case */ },
}
for _, test := range tests {
err := ValidatePolicy(test.policy, test.isPlus, false, false)
if err != nil {
t.Errorf("ValidatePolicy returned error %v for case: %s", err, test.msg)
}
}
}
Naming Convention

Two conventions are in use -- both are acceptable:

Policy/transport tests (policy_test.go, transportserver_test.go):

  • TestValidate<Thing>_PassesOnValidInput
  • TestValidate<Thing>_FailsOnInvalidInput

VirtualServer/general tests (virtualserver_test.go and most other files):

  • TestValidate<Thing> (valid input, often with subtests)
  • TestValidate<Thing>Fails (invalid input)
  • TestGenerate<Feature>
Snapshot Test Mechanics

Every package that uses snaps.MatchSnapshot needs exactly one TestMain that prunes stale snapshots. It lives in a single file per package (version1/template_test.go, version2/templates_test.go, charts/tests/helmunit_test.go) -- do not add a second one when you create a new test file in an existing package:

go
func TestMain(m *testing.M) {
snaps.Clean(m, snaps.CleanOpts{Sort: true})
}

Example snapshot test:

go
func TestVirtualServerForNginx(t *testing.T) {
t.Parallel()
executor := newTmplExecutorNGINX(t)
data, err := executor.ExecuteVirtualServerTemplate(&virtualServerCfg)
require.NoError(t, err)
snaps.MatchSnapshot(t, string(data))
}
Helper Conventions
  • Always call t.Parallel() at the start
  • Use t.Helper() in helper functions
  • Use github.com/google/go-cmp/cmp for deep struct comparison
  • Use github.com/gkampitakis/go-snaps/snaps for snapshot tests

Helm Tests

Location: charts/tests/

  • helmunit_test.go -- Helm snapshot tests using terratest + go-snaps
  • testdata/ -- values.yaml overrides per test scenario

Add a test values file in charts/tests/testdata/<feature>.yaml and a corresponding test case in helmunit_test.go.


Python Integration Tests

Location: tests/suite/

Markers must be registered

pytest runs with --strict-markers (pyproject.toml, [tool.pytest.ini_options] addopts). Any new @pytest.mark.<name> must be added to the markers list in pyproject.toml at the repository root or the whole suite errors out. If the marker should run in CI, also add it to the relevant smoke matrix in .github/data/matrix-smoke-*.json.

Test Class Pattern
python
@pytest.mark.policies
@pytest.mark.policies_myfeature
@pytest.mark.parametrize(
"crd_ingress_controller, virtual_server_setup",
[({"type": "complete", "extra_args": [...]},
{"example": "virtual-server", "app_type": "simple"})],
indirect=True,
)
class TestMyFeaturePolicies:
def test_basic_functionality(self, kube_apis, crd_ingress_controller,
virtual_server_setup, test_namespace):
# 1. Create policy from YAML
pol_name = create_policy_from_yaml(
kube_apis.custom_objects, yaml_src, test_namespace
)
try:
# 2. Patch VS to reference policy
patch_virtual_server_from_yaml(...)
# 3. Poll until the reload has taken effect; never sleep, then assert once
resp = retry_get_until_status_code(url, virtual_server_setup.vs_host, 200)
assert resp.status_code == 200 # the helper returns the last response even if it never matched
assert "Expected-Header" in resp.headers
finally:
# 4. Cleanup runs even when an assert fails
delete_policy(kube_apis.custom_objects, pol_name, test_namespace)
patch_virtual_server_from_yaml(...) # restore original
Fixtures and Utilities
  • Common fixtures: kube_apis, crd_ingress_controller, virtual_server_setup, test_namespace
  • Fixtures: tests/suite/fixtures/ (setup/teardown lifecycle)
  • Utilities: tests/suite/utils/ (create_policy_from_yaml, patch_virtual_server_from_yaml, delete_policy, retry_get_until_status_code)
  • Prefer polling over fixed sleeps, see "Waiting for config changes" below
Waiting for config changes

A config change reloads NGINX. A request that lands during the reload can be dropped, and a fixed wait_before_test() before one assertion only passes if the reload is faster than the sleep. Details and the failure data: docs/developer/e2e-flaky-tests.md.

  • After a change that reloads, poll with retry_get_until_status_code, retry_get_until_body_contains, or retry_get (one request, retried only on ConnectionError). They are in tests/suite/utils/resources_utils.py. wait_and_assert_status_code and send_malicious_request_with_retry also tolerate dropped connections. The retry_get_until_* helpers return the last response even if it never matched, so still assert on it.
  • For non-HTTP conditions use the existing waiters: wait_for_event, wait_for_resource_status, wait_for_reload, wait_until_all_pods_are_ready, ensure_response_from_backend.
  • Keep wait_before_test() only when the wait is the point of the test (rate-limit windows, asserting something does not happen).
  • Do not add @pytest.mark.flaky. It reruns the whole test and hides real regressions.
  • If a test catches requests.exceptions.SSLError (mTLS), put that except before except ConnectionError, because SSLError is a subclass.
  • The nginx-config ConfigMap lives for the whole session. A test that changes it restores it in a fixture or finally, not at the end of the test body, or a later unrelated test fails. tests/conftest.py prints Leaked nginx-config when a class leaves it changed. The IC Deployment is recreated per class, so replica counts do not leak across classes.
File Naming
  • test_<feature>_policies_vs.py -- VirtualServer policy tests
  • test_<feature>_policies_vsr.py -- VirtualServerRoute policy tests
  • test_<feature>_policies_ingress.py -- Ingress policy tests
Test Data

Store YAML manifests in tests/data/<feature>/.


Generated Artifacts Verified by CI

The verify-codegen job in ci.yml re-runs each generator and diffs a specific path. Run the matching target and commit the result:

You changedRunPath CI diffs
pkg/apis/**/types.gomake update-codegenpkg/**
pkg/apis/** kubebuilder markersmake update-crdsconfig/crd/bases and config/crd/upstream only
Telemetry Data / NICResourceCounts in internal/telemetry/exporter.gomake telemetry-schemainternal/telemetry
Any import / dependencygo mod tidygo.mod, go.sum
Any .tmpl or template structmake test-update-snapsnot checked by verify-codegen -- fails in unit-tests instead

The checks are path-scoped, not repository-wide. make update-crds also rewrites deploy/crds*.yaml and docs/crd/, but CI never diffs those paths -- forgetting to commit them produces a green build and stale published CRD bundles. Verify them yourself with git status after regenerating.

charts/nginx-ingress/crds is a symlink to config/crd/bases/ -- never edit it directly.


Gotchas

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 95 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
5,081
Repository forks
2,051
7-day trend score
43

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/nginx/kubernetes-ingress/nic-testing/badge)](https://verified-skill.com/skills/nginx/kubernetes-ingress/nic-testing)

Something wrong with this skill or its page? Tell us.