cloudtest

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const Contract = "1.4.0"

Contract is the version the fake checks against.

View Source
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 AccessTok

type AccessTok struct {
	// contains filtered or unexported fields
}

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

type AgentActivity struct {
	Agent string `json:"agent"`
	State string `json:"state"`
}

AgentActivity is one agent in it.

type DeviceCode

type DeviceCode struct {
	User     string
	State    string // pending, approved, denied, suspended
	Interval int
	SlowDown int // answer slow_down this many more times
}

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 New

func New(t *testing.T) *Fake

func (*Fake) AddMachine

func (f *Fake) AddMachine(name, state, key, room string) *Machine

addMachine adds a running machine whose gateway uses key.

func (*Fake) Approve

func (f *Fake) Approve(state string)

approve approves the newest device code, as a person would.

func (*Fake) ApproveWhenAsked

func (f *Fake) ApproveWhenAsked(state string)

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) Count

func (f *Fake) Count(route string) int

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

func (f *Fake) SetMachine(id string, fn func(m *Machine))

func (*Fake) StartGateway

func (f *Fake) StartGateway(t *testing.T, serverSocket string) *Gateway

func (*Fake) Total

func (f *Fake) Total() int

func (*Fake) URL

func (f *Fake) URL() string

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.

func (*Gateway) Stop

func (g *Gateway) Stop()

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL