Documentation
¶
Overview ¶
Package cloudtest is a fake Conch Cloud control plane for conch's tests: the client side of the contract on httptest — the device flow, tokens that rotate (a reused refresh token revokes the device, as the real one does), machines, connect with single-use tickets — and a relay that checks those tickets in front of conch's own. Every request and answer is checked against the contract when a conch-cloud checkout is beside this one (internal/cloudcontract). Tests import it; nothing conch ships does.
Index ¶
- Constants
- func WriteJSON(w http.ResponseWriter, status int, v any)
- func WriteProblem(w http.ResponseWriter, status int, code, detail string)
- type AccessTok
- type Activity
- type AgentActivity
- type DeviceCode
- type Fake
- func (f *Fake) AddMachine(name, state, key, room string) *Machine
- func (f *Fake) Approve(state string)
- func (f *Fake) ApproveWhenAsked(state string)
- func (f *Fake) Count(route string) int
- func (f *Fake) JoinGateway(t *testing.T, serverSocket string, key noise.DHKey, secret string) *Gateway
- func (f *Fake) SetMachine(id string, fn func(m *Machine))
- func (f *Fake) StartGateway(t *testing.T, serverSocket string) *Gateway
- func (f *Fake) Total() int
- func (f *Fake) URL() string
- type Gateway
- type Machine
Constants ¶
const Contract = "1.4.0"
Contract is the version the fake checks against.
const URLEnv = "CONCH_CLOUD_URL"
URLEnv is internal/cloud's, set to the fake's address.
Variables ¶
This section is empty.
Functions ¶
func WriteJSON ¶
func WriteJSON(w http.ResponseWriter, status int, v any)
WriteJSON answers v as JSON.
func WriteProblem ¶
func WriteProblem(w http.ResponseWriter, status int, code, detail string)
WriteProblem answers a problem+json.
Types ¶
type Activity ¶
type Activity struct {
Agents []AgentActivity `json:"agents"`
ClientsAttached int `json:"clients_attached"`
ReportedAt time.Time `json:"reported_at"`
}
Activity is a machine's last activity report.
type AgentActivity ¶
AgentActivity is one agent in it.
type DeviceCode ¶
type Fake ¶
type Fake struct {
Srv *httptest.Server
Spec *cloudcontract.Spec
Mu sync.Mutex // held while changing the fields below
Forbidden bool // any request fails the test
BadTickets bool // the relay refuses every ticket
Codes map[string]*DeviceCode
Access map[string]AccessTok
Revoked map[string]bool
AccessTTL int
Machines map[string]*Machine
Keys map[string]string // machine → its server key
Rooms map[string]string // machine → room
// relay is the relay the fake's connect names, with its ticket check.
Relay *httptest.Server
// contains filtered or unexported fields
}
Fake is the control plane's client side on httptest: device flow, tokens that rotate (a reused refresh token revokes the device, as the real one does), machines, connect with single-use tickets, and a relay that checks them. Every request and answer is checked against the contract when it is there.
func (*Fake) AddMachine ¶
addMachine adds a running machine whose gateway uses key.
func (*Fake) ApproveWhenAsked ¶
ApproveWhenAsked waits, in the background, for a sign-in to be asked for and then answers it with state. It waits for the code itself, not the request: serve counts a request before it makes the code, so an answer given in between found no code to answer, and the sign-in then waited out the code's ten minutes — TestMoveWakesCloudDestination failing at 601s on a loaded machine.
func (*Fake) JoinGateway ¶
func (f *Fake) JoinGateway(t *testing.T, serverSocket string, key noise.DHKey, secret string) *Gateway
joinGateway is a gateway with this key in this room: the same machine coming back.
func (*Fake) SetMachine ¶
type Gateway ¶
type Gateway struct {
Key string // its public key, base64url
Room string
DH noise.DHKey
Secret string
// contains filtered or unexported fields
}
gateway is a machine's side: cloudagent's tunnel handler behind a link to the fake's relay, with the conch server socket given.
type Machine ¶
type Machine struct {
ID string `json:"id"`
Name string `json:"name"`
Size string `json:"size"`
Region string `json:"region"`
State string `json:"state"`
StateDetail string `json:"state_detail,omitempty"`
Sleep map[string]int `json:"sleep"`
ServerKey string `json:"server_key,omitempty"`
CreatedAt time.Time `json:"created_at"`
Activity *Activity `json:"activity,omitempty"`
}
Machine is a machine as the fake keeps and answers it.