Test unit and lint

From GoogleCloudPlatform/k8s-bridge · View interactive version

Test unit and lint is an AI agent skill from the GitHub repository GoogleCloudPlatform/k8s-bridge. Writes and runs table-driven Go unit tests, envtest controller integration tests, Slurm REST client mocks, and static analysis linters via make test, make fmt, make vet, and make lint. Use when adding or debugging package-level tests, mocking Slurm REST API responses, or fixing lint and formatting f

How to use this skill

Skill file

Unit Testing, `envtest`, and Linting Workflow (`test-unit-and-lint`)

1. Preconditions & Inputs

Before writing or running unit/envtest tests and linters, inspect the existing test and mock helpers:


2. Guardrails

1. Use &utils.SlurmClient{} (inspect test/utils/slurmmock.go for supported job/node state and error-injection fields) when testing SlurmPoller, SlurmJobReconciler, or JobTeardownReconciler. It does not implement controller ping or inject List errors.

2. Use slurmclientfake.NewClientBuilder().WithInterceptorFuncs(...).Build() (github.com/SlinkyProject/slurm-client/pkg/client/fake) when testing controller ping in SlurmClientReconciler or custom List error interceptors.


3. Step-by-Step Procedure

Step 1: Write Unit or `envtest` Specs

  1. Fake-client unit tests (internal/controller/slurmjob/, internal/controller/slurmclientsync/, internal/clientmap/, internal/metrics/): Add table-driven tests alongside the package under test using the helpers in Section 1.
  2. envtest integration specs (internal/controller/workloadmixing/): Add Ginkgo specs in workloadmixing_controller_test.go (if running go test ./internal/controller/workloadmixing/... directly instead of make test, run make manifests setup-envtest first).

4. Verification

Run the unit/envtest suite and linters (use make lint-fix for auto-fixable lint issues):

make fmt vet lint test

5. Handoffs & Related Skills

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.