Skip to content

Add live tests against the real SendGrid API and verified APIs - #100

Merged
kenzo0107 merged 12 commits into
mainfrom
add-live-api-tests
Oct 7, 2026
Merged

kenzo0107 merged 12 commits into
mainfrom
add-live-api-tests

Conversation

@kenzo0107

@kenzo0107 kenzo0107 commented Oct 7, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds live tests that call the real SendGrid API, and includes only the new or changed APIs that could be verified against it.

Unit tests with mocked responses cannot catch differences from the real API (undefined fields, type mismatches, array vs. object). The live tests exposed several such differences, which are fixed here.

Live tests (mise run test-live)

  • Isolated by the live build tag, so they never run with mise run test or in CI.
  • All tests abort unless SENDGRID_LIVE_USERNAME matches the API key's account.
  • Responses are compared with the structs, and every undefined field is reported as a JSON path.
  • Updates are verified by re-fetching the resource; deletions are verified by confirming it is gone.
  • Accounts that do not match SENDGRID_LIVE_PRIVATE_USERNAME are treated as shared, and response bodies are never logged for them.

Differences found against the real API

Target Fix
GetLegacySenders / GetMarketingSenders The API returns a bare array, so the return types are now []*LegacySender / []*MarketingSender
Sender verified Returned as a {status, reason} object, so it is now *LegacySenderVerified / *MarketingSenderVerified
Template Version Added active
OutputGetAuthenticatedDomain Added last_validation_attempt_at
Legacy recipient list responses Added recipient_count
User Account Added is_reseller_customer / is_hard_limit / authy_id / multifactor_phone / type / userid
GetAllAuthenticatedDomainsAssociatedWithSubuser username is now URL-encoded

New APIs

  • Pre-built Design, Bounce Classification, subuser-related Domain Authentication
  • Scopes / User Account
  • Legacy Sender / List / Segment / Campaign
  • Marketing Sender
  • Engagement Quality / IP Address Management / Partner Settings

Methods that send email, incur charges, or cannot be undone were not run against the real API. These include Sender creation and verification emails, Campaign send/schedule, IP and pool changes, and User updates.

Task runner migration

Migrates the Makefile and .tool-versions to mise. The test workflow already used mise-action, so the lint workflow now does too.

Test plan

  • mise run test (unit tests)
  • golangci-lint run --build-tags live --tests ./...
  • Every commit builds and passes unit tests on its own
  • mise run test-live on a private test account (0 failures)
  • mise run test-live on a shared account (18 passed, 0 failed)
    • Snapshots of existing resources (Template / Suppression Group / List / Segment / Campaign / Recipient / Sender) are identical before and after the run
    • No resources created by the tests remain

🤖 Generated with Claude Code

kenzo0107 and others added 12 commits October 7, 2026 09:30
… mise

The test workflow already uses mise-action, so align the lint workflow and local commands with it.

- Port Makefile targets to mise.toml tasks and remove Makefile and .tool-versions
- Switch the lint workflow from setup-go + make to mise-action + mise run lint
- Ignore mise.local.toml / mise.*.local.toml, which hold secrets

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The real API response includes active (0/1), but the struct had no field for it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Add GetPreBuiltDesign / DuplicatePreBuiltDesign
- Verified against the real API: the duplicated design is retrievable and returns 404 after deletion

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Add GetBounceClassifications / GetBounceClassificationsByDomain
- Verified that real API responses match the structs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…elds

- Add EmailDNSRecordsToCoworker / AssociateAuthenticatedDomainWithSubuserMultiple / GetAllAuthenticatedDomainsAssociatedWithSubuser
- Add last_validation_attempt_at to OutputGetAuthenticatedDomain, as returned by the real API
- URL-encode username, since subuser names containing & or # broke the query string

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Add fields found in real API responses: is_reseller_customer / is_hard_limit / authy_id / multifactor_phone / type / userid
- Update APIs (email, password, username, profile) were not run against the real API because they cannot be undone

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Verified create, re-fetch after update, and 404 after delete against the real API (List / Segment / Campaign)
- GET /senders returns a bare array, so GetLegacySenders now returns []*LegacySender
- verified is returned as a {status, reason} object, not a bool, so add LegacySenderVerified
- Add recipient_count to recipient list responses
- Sender create/update/resend verification and Campaign send/schedule were not run because they send email

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- GET /marketing/senders returns a bare array, so GetMarketingSenders now returns []*MarketingSender
- verified is returned as a {status, reason} object, so add MarketingSenderVerified
- Create/update/resend verification were not run against the real API because they send email

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Verified that real API responses match the structs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Verified that real API responses for the read APIs match the structs
- Adding IPs, creating/updating/deleting pools, and assigning subusers were not run because they affect delivery and billing

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Verified that real API responses match the structs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Unit tests with mocked responses cannot catch differences from the real API (undefined fields, type mismatches, array vs. object).

- Isolated by the live build tag from regular tests and CI; run with mise run test-live
- Abort all tests unless SENDGRID_LIVE_USERNAME matches the API key's account
- Compare responses with the structs and list every undefined field as a JSON path
- Verify updates by re-fetching and deletions by confirming the resource is gone
- Treat accounts not matching SENDGRID_LIVE_PRIVATE_USERNAME as shared and do not log response bodies

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kenzo0107 kenzo0107 changed the title 実 SendGrid API を叩く live 試験を追加し、検証済みの API を追加 Add live tests against the real SendGrid API and verified APIs Oct 7, 2026
@kenzo0107
kenzo0107 merged commit a1a40dc into main Oct 7, 2026
3 checks passed
@kenzo0107
kenzo0107 deleted the add-live-api-tests branch October 7, 2026 00:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant