Why --- - Sprintf(*p.Title) fed the title as a format string — % in titles broke the String() method; also panicked on nil Title. - internal/applications.buildSummary used RE2-unsupported `(?= ...)` lookahead inside regexp.MustCompile, panicking the first time the applications-sync path was exercised on Go 1.23+. - Query() duplicated the auth-expiry check inline while ensureToken() already handled it — two code paths drifted. - Request.Debug split Query() into two branches that both unmarshalled into the same target value. Dead code. - httptest fixtures that emulated OnlyOffice endpoints were lying to us: they passed locally yet never caught a single real protocol regression. What ---- - Project.String(): nil-safe, no Sprintf format-string interpretation. - buildSummary regex: RE2-safe non-capturing trailing delimiter `(?:\n## |$)` replaces the lookahead. - Query() routes through ensureToken(); body marshalling factored into an unexported requestBodyReader(). Debug flag retained for backwards compatibility, documented as a no-op, to be removed at next major. - Dropped Debug: true stray flags in GetTasks/UpdateProjectTask. - Deleted httptest-based OnlyOffice mocks. unit_test.go is now pure Go (parsers, helpers, env aliases, ctx cancellation against an unroutable address). client_test.go is `//go:build integration` and runs against a real OnlyOffice, skipping cleanly without ONLYOFFICE_URL/USER/PASS. - AGENTS.md + .cursor/rules/no-synthetic-mocks.mdc document the new testing policy. Verified -------- - `go test ./...` green (15 unit tests across package + internal). - `go test -tags=integration ./...` green against live office.produktor.io (5 integration tests: auth, projects, lifecycle, calendar+CRM read, task list). - inventar-sync smoke dry-run against live OO project 33 + Gitea found 30 tasks, 0 mutations. Made-with: Cursor
39 lines
1.6 KiB
Plaintext
39 lines
1.6 KiB
Plaintext
---
|
|
description: No synthetic OnlyOffice/Gitea mocks; prefer real integration tests
|
|
globs:
|
|
- "**/*_test.go"
|
|
alwaysApply: false
|
|
---
|
|
# Testing policy — no synthetic vendor mockups
|
|
|
|
When authoring tests under `github.com/eslider/go-onlyoffice`, do **not**
|
|
build `httptest.NewServer` fixtures that emulate OnlyOffice, Gitea, or any
|
|
other third-party API. Simulated vendor responses drift from reality, give
|
|
false green signals, and hide protocol changes.
|
|
|
|
## What to do instead
|
|
|
|
1. **Unit tests** — pure Go, no network. Use them for parsers, encoders,
|
|
struct conversions, pure helpers. No `httptest` that fakes the vendor.
|
|
2. **Integration tests** — `//go:build integration` tag in a `*_integration_test.go`
|
|
file. Read credentials from env:
|
|
- `ONLYOFFICE_URL` / `ONLYOFFICE_HOST`
|
|
- `ONLYOFFICE_USER` / `ONLYOFFICE_NAME`
|
|
- `ONLYOFFICE_PASS` / `ONLYOFFICE_PASSWORD`
|
|
Call `t.Skip("ONLYOFFICE_URL not set")` when credentials are absent so the
|
|
regular `go test ./...` stays green in CI.
|
|
3. **Run integration**: `go test -tags=integration ./...`.
|
|
4. **Every new endpoint** ships with an integration test in the same PR.
|
|
|
|
## Narrow exception
|
|
|
|
`httptest.NewServer` is OK when verifying the **caller's own** HTTP
|
|
behaviour (e.g. a user's handler or middleware we are wrapping). It is **not**
|
|
OK when the test server is pretending to be OnlyOffice or Gitea.
|
|
|
|
## Migrating existing tests
|
|
|
|
If you find a test that handles routes like `/api/2.0/...` and returns canned
|
|
JSON, convert it to an integration test (or delete it if the behaviour is
|
|
already covered by integration).
|