# Generate Mocks

> Use when generating testify mocks for an interface. Ensures the interface is registered in .mockery.yml, runs make mocks, and verifies the output file.

- Skill: `epam/generate-mocks` (Agent Skill)
- Install (CLI): `npx skillmds@latest add epam/generate-mocks`
- Raw SKILL.md: https://api.skillmd.com/api/skills/epam/generate-mocks/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: epam (https://skillmd.com/u/epam)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/epam/generate-mocks

---


## Your task

Generate mocks for one or more interfaces. `$ARGUMENTS` contains the interface name(s) to add/verify (may be empty — in that case just regenerate all existing mocks).

Work through all steps in order.

---

## Step 1 — Read .mockery.yml

Read `.mockery.yml` to understand the current package/interface registrations.

Key structure:
```yaml
packages:
  github.com/epam/edp-keycloak-operator/<pkg-path>:
    interfaces:
      InterfaceName: {}
```

Generated filename pattern: `{{ .InterfaceName | snakecase }}_generated.mock.go`
Output directory: `<package_dir>/mocks/`

---

## Step 2 — Locate the interface in source (skip if `$ARGUMENTS` is empty)

Use Grep to find `type <InterfaceName> interface` in `pkg/` and `internal/`.

Derive the Go import path from the file path:
- Use the **directory** of the file (not the file itself)
- Prepend `github.com/epam/edp-keycloak-operator/`
- Example: `pkg/client/keycloakapi/contracts.go` → package `github.com/epam/edp-keycloak-operator/pkg/client/keycloakapi`

---

## Step 3 — Update .mockery.yml if needed (skip if `$ARGUMENTS` is empty)

Add only the missing entries with a targeted Edit; the file registers every mocked interface in the repo, and a rewrite drops the ones outside this task:

- Interface already registered → nothing to do, skip to Step 4.
- Package present, interface missing → insert `      InterfaceName: {}` under its `interfaces:` block.
- Package not present → append a new package entry at the end of the `packages:` block.

---

## Step 4 — Run make mocks

```
make mocks
```

---

## Step 5 — Verify output

Use Glob to confirm the generated file exists at the expected path.

Expected path: `<package_filesystem_dir>/mocks/<interface_name_snakecase>_generated.mock.go`

Example: `UsersClient` in `pkg/client/keycloakapi/` → `pkg/client/keycloakapi/mocks/users_client_generated.mock.go`

Report the verified path to the user.

