Skip to main content
Each recipe includes the problem, solution code, and rationale. For LDAP paging and nested pagination, see Pagination patterns.

Configurable base URL for mocks

Problem: Test your connector against a mock server without hitting production. Solution: Add a base URL field to your configuration, and give it a default that points at the real API:
After you run make generate, the generated configuration struct has a BaseUrl field. Pass it to your client:
Usage:
Why: Without a configurable base URL, you can’t test without hitting production. That breaks CI and risks exposing production data. See Define your configuration for how fields become flags.

Insecure TLS for local testing

Problem: Test against a mock server that uses a self-signed certificate. Solution: Add a bool field, and apply it when you build the HTTP client:
Usage:
Why: Mock servers often use self-signed certificates. An --insecure flag lets you test without installing a custom certificate authority.
Never use --insecure in production. It’s strictly for local testing with mock servers.

Unit-test a resource builder

Problem: Verify that a builder lists the right resources, including across pages, without running a full sync. Solution: Call the builder’s methods directly with a fake client, and loop until the page token is empty:
require is github.com/stretchr/testify/require. Have the fake client return small pages, so the loop crosses a page boundary. Call Entitlements and Grants the same way, passing the resource under test. Why: Testing the page loop catches token bugs before they reach a real sync. A V2 builder returns its next token in results.NextPageToken, and nil results mean the same as an empty token.

Use the SDK test helpers

The pkg/test package has helpers for common checks:
These helpers accept the V1 interfaces, ResourceSyncerLimited and ResourceProvisionerLimited. A V2 builder doesn’t satisfy them, so for V2 builders write the page loop yourself, as in the previous recipe.

Run and inspect with the baton CLI

Problem: Check a connector end to end against a real or mock API. Solution: Run the connector to produce a sync file, then inspect it with the baton CLI:
To iterate on one part of a sync, limit it:
To test provisioning against a sync file, see Test provisioning locally. Why: The baton CLI reads the same file that C1 would receive, so you see what your connector actually produced, including IDs and parent links.