Documentation
¶
Overview ¶
Package cloudflaretest is an in-process fake of the slice of the Cloudflare v4 API the cloudflare hosting adapter calls, for tests only. No test in this repository reaches the real service: the adapter and the verb above it are exercised against this server, and every route it answers can be made to fail, so each error path is a test rather than a hope.
The fake answers the documented shapes (the v4 envelope: success, errors, result, result_info) for exactly these routes:
GET /accounts
GET /accounts/{account}/workers/workers
POST /accounts/{account}/workers/workers
GET /accounts/{account}/workers/domains
PUT /accounts/{account}/workers/domains
GET /accounts/{account}/workers/subdomain
Anything else is a 404, so a request the adapter was not written to make fails the test that provoked it.
Index ¶
Constants ¶
const ( ListAccounts = "GET accounts" ListWorkers = "GET workers" CreateWorker = "POST workers" ListDomains = "GET domains" AttachDomain = "PUT domains" GetSubdomain = "GET subdomain" )
Route keys name a route for Fail and for the call log.
const Account = "0123456789abcdef0123456789abcdef"
Account is the one account the default fake holds.
const Subdomain = "example-sub"
Subdomain is the account's workers.dev subdomain.
const Token = "cf-fake-token-0000000000000000000000000000"
Token is the credential the fake accepts. Any other bearer is a 403.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Server ¶
type Server struct {
*httptest.Server
Mu sync.Mutex
// Accounts the token reaches.
Accounts []string
// Workers by name.
Workers map[string]bool
// Domains maps a hostname to the Worker it is routed to.
Domains map[string]string
// Fail answers a route with this HTTP status instead of serving it.
Fail map[string]int
// PageSize splits the Workers list into pages of this size (0 = one page).
PageSize int
// Calls is every request received, as its route key.
Calls []string
// Bodies holds each write's decoded JSON body, keyed by route.
Bodies map[string][]map[string]any
// Auth records every Authorization header value received, so a test can
// assert the credential went where it should and nowhere else.
Auth []string
}
Server is the fake. Its fields are the host's state; lock with Mu to read them while a request may be in flight.