Help us shape the future of Go! Take the 2026 Go Developer Survey

admintest

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package admintest is a stand-in for go-fileshare/portal and the fileshare servers behind it, for tests: in one process, with the portal's rules where the console depends on them.

  • every call must carry Portal-Request: 1, or it is refused (403);
  • a session holds tokens only for the servers its last refresh named, and a call to another answers 401 with Portal-Refresh: <server>;
  • refreshes are counted, and two that overlap are reported, because a provider that rotates refresh tokens would end the login there.

Behind it each server is a real Connect server (connect-go, the same generated handler interface fileshare implements) over a map of shares.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Share

func Share(name, dir string, subject string, write bool) *v1.Share

Share is a directory share with one grant, enabled.

Types

type Portal

type Portal struct {
	*httptest.Server

	Refreshes   atomic.Int64
	Overlapping atomic.Int64 // refreshes that began while another ran

	// Delay makes each refresh take this long, so that overlaps can happen.
	Delay time.Duration
	// MaxTokens, when > 0, refuses a refresh for more servers (413), as the
	// portal does past its cookie budget.
	MaxTokens int
	// NoHeader counts calls that came without Portal-Request.
	NoHeader atomic.Int64
	// contains filtered or unexported fields
}

Portal is the fake portal.

func New

func New(loggedIn bool, servers ...*Server) *Portal

New starts a fake portal with the given servers, logged in or not.

func (*Portal) Expire

func (p *Portal) Expire()

Expire drops every token, as time passing would.

func (*Portal) Logout

func (p *Portal) Logout()

Logout ends the session, as an expired login would.

func (*Portal) Tokens

func (p *Portal) Tokens() []string

Tokens is the servers the session holds a token for.

type Server

type Server struct {
	adminv1connect.UnimplementedAdminServiceHandler
	ID, Label string
	Reachable bool

	// Calls counts the calls that reached this server.
	Calls atomic.Int64
	// Fail, when set, is answered to every call.
	Fail error
	// contains filtered or unexported fields
}

Server is one fake fileshare server.

func NewServer

func NewServer(id, label string, shares ...*v1.Share) *Server

NewServer is a fake fileshare server with these shares.

func (*Server) CreateShare

func (*Server) DeleteShare

func (*Server) DisableShare

func (*Server) EnableShare

func (*Server) GetServerInfo

func (*Server) Grant

func (s *Server) Grant(_ context.Context, r *v1.GrantRequest) (*v1.GrantResponse, error)

func (*Server) ListShares

func (*Server) Names

func (s *Server) Names() []string

Names is the shares on s, sorted.

func (*Server) Revoke

Jump to

Keyboard shortcuts

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