mockapi

package
v0.0.0-...-f3f6ddd Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package mockapi provides mocks of the HTTP API for use in integration tests.

Index

Constants

This section is empty.

Variables

View Source
var ValidAPITokens = []string{"api-token-1"}

Functions

func NewAuthServer

func NewAuthServer(t *testing.T) *httptest.Server

NewAuthServer creates a new mock authentication server. The caller must call Close() on the server when finished.

func NumericID

func NumericID() string

NumericID generates a random numeric ID.

func ProjectID

func ProjectID() string

ProjectID generates a random project ID.

Types

type Activity

type Activity struct {
	ID   string `json:"id"`
	Type string `json:"type"`

	State             string    `json:"state"`
	Result            string    `json:"result"`
	CompletionPercent int       `json:"completion_percent"`
	CompletedAt       time.Time `json:"completed_at"`
	StartedAt         time.Time `json:"started_at"`

	Project      string   `json:"project"`
	Environments []string `json:"environments"`

	Description string `json:"description"`
	Text        string `json:"text"`

	Payload any `json:"payload"`

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

type App

type App struct {
	Name string `json:"name"`
	Type string `json:"type"`
	Size string `json:"size"`
	Disk int    `json:"disk"`

	Mounts map[string]Mount `json:"mounts"`
}

type Backup

type Backup struct {
	ID            string    `json:"id"`
	EnvironmentID string    `json:"environment"`
	Status        string    `json:"status"`
	Safe          bool      `json:"safe"`
	Restorable    bool      `json:"restorable"`
	Automated     bool      `json:"automated"`
	CommitID      string    `json:"commit_id"`
	ExpiresAt     time.Time `json:"expires_at"`

	Links HalLinks `json:"_links"`

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

type CanCreateRequiredAction

type CanCreateRequiredAction struct {
	Action string `json:"action"`
	Type   string `json:"type"`
}

type CanCreateResponse

type CanCreateResponse struct {
	CanCreate bool   `json:"can_create"`
	Message   string `json:"message"`

	RequiredAction *CanCreateRequiredAction `json:"required_action"`
}

type Commands

type Commands struct {
	Start string `json:"start"`
}

type Deployment

type Deployment struct {
	WebApps  map[string]App    `json:"webapps"`
	Services map[string]App    `json:"services"`
	Workers  map[string]Worker `json:"workers"`

	Routes map[string]any `json:"routes"`

	Links HalLinks `json:"_links"`
}

type EnvLevelVariable

type EnvLevelVariable struct {
	Variable

	IsEnabled     bool `json:"is_enabled"`
	Inherited     bool `json:"inherited"`
	IsInheritable bool `json:"is_inheritable"`
}

type Environment

type Environment struct {
	ID          string    `json:"id"`
	Name        string    `json:"name"`
	MachineName string    `json:"machine_name"`
	Title       string    `json:"title"`
	Type        string    `json:"type"`
	Status      string    `json:"status"`
	Parent      any       `json:"parent"`
	Project     string    `json:"project"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
	Links       HalLinks  `json:"_links"`
	// contains filtered or unexported fields
}

func (*Environment) SetCurrentDeployment

func (e *Environment) SetCurrentDeployment(d *Deployment)

func (*Environment) SetSetting

func (e *Environment) SetSetting(key string, val any)
type HALLink struct {
	HREF string `json:"href"`
}
type HalLinks map[string]HALLink
func MakeHALLinks(nameAndPath ...string) HalLinks

MakeHALLinks helps make a list of HAL links out of arguments in the format name=path.

type Handler

type Handler struct {
	*chi.Mux
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler(t *testing.T) *Handler

func (*Handler) SetCanCreate

func (s *Handler) SetCanCreate(orgID string, r *CanCreateResponse)

func (*Handler) SetEnvLevelVariables

func (s *Handler) SetEnvLevelVariables(projectID, environmentID string, vars []*EnvLevelVariable)

func (*Handler) SetEnvironments

func (s *Handler) SetEnvironments(envs []*Environment)

func (*Handler) SetMyUser

func (s *Handler) SetMyUser(u *User)

func (*Handler) SetOrgs

func (s *Handler) SetOrgs(orgs []*Org)

func (*Handler) SetProjectActivities

func (s *Handler) SetProjectActivities(projectID string, activities []*Activity)

func (*Handler) SetProjectBackups

func (s *Handler) SetProjectBackups(projectID string, backups []*Backup)

func (*Handler) SetProjectVariables

func (s *Handler) SetProjectVariables(projectID string, vars []*Variable)

func (*Handler) SetProjects

func (s *Handler) SetProjects(pros []*Project)

func (*Handler) SetUserGrants

func (s *Handler) SetUserGrants(grants []*UserGrant)

type Mount

type Mount struct {
	Source     string `json:"source"`
	SourcePath string `json:"source_path"`
}

type Org

type Org struct {
	ID           string   `json:"id"`
	Type         string   `json:"type"`
	Name         string   `json:"name"`
	Label        string   `json:"label"`
	Owner        string   `json:"owner_id"`
	Capabilities []string `json:"capabilities"`
	Links        HalLinks `json:"_links"`
}

func (*Org) AsRef

func (o *Org) AsRef() *OrgRef

type OrgRef

type OrgRef struct {
	ID    string `json:"id"`
	Type  string `json:"type"`
	Name  string `json:"name"`
	Label string `json:"label"`
	Owner string `json:"owner_id"`
}

type Project

type Project struct {
	ID            string            `json:"id"`
	Title         string            `json:"title"`
	Region        string            `json:"region"`
	Organization  string            `json:"organization"`
	Vendor        string            `json:"vendor"`
	Repository    ProjectRepository `json:"repository"`
	DefaultBranch string            `json:"default_branch"`
	Links         HalLinks          `json:"_links"`
	CreatedAt     time.Time         `json:"created_at"`
	UpdatedAt     time.Time         `json:"updated_at"`

	Subscription ProjectSubscriptionInfo `json:"subscription,omitempty"`

	SubscriptionID string `json:"-"`
}

func (*Project) AsRef

func (p *Project) AsRef() *ProjectRef

type ProjectRef

type ProjectRef struct {
	ID             string    `json:"id"`
	Region         string    `json:"region"`
	Title          string    `json:"title"`
	Status         string    `json:"status"`
	OrganizationID string    `json:"organization_id"`
	SubscriptionID string    `json:"subscription_id"`
	Vendor         string    `json:"vendor"`
	CreatedAt      time.Time `json:"created_at"`
	UpdatedAt      time.Time `json:"updated_at"`
}

type ProjectRepository

type ProjectRepository struct {
	URL string `json:"url"`
}

type ProjectSubscriptionInfo

type ProjectSubscriptionInfo struct {
	LicenseURI string `json:"license_uri,omitempty"`

	Plan          string `json:"plan,omitempty"`
	Environments  int    `json:"environments,omitempty"`
	Storage       int    `json:"storage,omitempty"`
	IncludedUsers int    `json:"included_users,omitempty"`
	UserLicenses  int    `json:"user_licenses,omitempty"`

	ManagementURI string `json:"subscription_management_uri,omitempty"`

	Restricted bool `json:"restricted,omitempty"`
	Suspended  bool `json:"suspended,omitempty"`
}

type ProjectUserGrant

type ProjectUserGrant struct {
	ProjectID      string    `json:"project_id"`
	OrganizationID string    `json:"organization_id"`
	UserID         string    `json:"user_id"`
	Permissions    []string  `json:"permissions"`
	GrantedAt      time.Time `json:"granted_at"`
	UpdatedAt      time.Time `json:"updated_at"`
}

type Subscription

type Subscription struct {
	ID            string   `json:"id"`
	Links         HalLinks `json:"_links"`
	ProjectID     string   `json:"project_id"`
	ProjectRegion string   `json:"project_region"`
	ProjectTitle  string   `json:"project_title"`
	Status        string   `json:"status"`
	ProjectUI     string   `json:"project_ui"`
}

type User

type User struct {
	ID string `json:"id"`

	Deactivated bool `json:"deactivated"`

	Namespace string `json:"namespace"`

	Username      string `json:"username"`
	FirstName     string `json:"first_name"`
	LastName      string `json:"last_name"`
	Email         string `json:"email"`
	EmailVerified bool   `json:"email_verified"`
	Picture       string `json:"picture"`
	Country       string `json:"country"`

	PhoneNumberVerified bool `json:"phone_number_verified"`

	MFAEnabled bool `json:"mfa_enabled"`
	SSOEnabled bool `json:"sso_enabled"`

	ConsentMethod string    `json:"consent_method"`
	ConsentedAt   time.Time `json:"consented_at"`

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

type UserGrant

type UserGrant struct {
	ResourceID     string    `json:"resource_id"`
	ResourceType   string    `json:"resource_type"`
	OrganizationID string    `json:"organization_id"`
	UserID         string    `json:"user_id"`
	Permissions    []string  `json:"permissions"`
	GrantedAt      time.Time `json:"granted_at"`
	UpdatedAt      time.Time `json:"updated_at"`
}

type UserRef

type UserRef struct {
	ID        string `json:"id"`
	Email     string `json:"email"`
	Username  string `json:"username"`
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
}

type Variable

type Variable struct {
	Name           string `json:"name"`
	Value          string `json:"value,omitempty"`
	IsSensitive    bool   `json:"is_sensitive"`
	VisibleBuild   bool   `json:"visible_build"`
	VisibleRuntime bool   `json:"visible_runtime"`

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`

	Links HalLinks `json:"_links"`
}

type Worker

type Worker struct {
	App
	Worker WorkerInfo `json:"worker"`
}

type WorkerInfo

type WorkerInfo struct {
	Commands Commands `json:"commands"`
}

Jump to

Keyboard shortcuts

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