proxytest

package
v0.0.0-...-c56160f Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Overview

Package proxytest supports testing with the proxy.

Index

Constants

This section is empty.

Variables

View Source
var CommitTime = time.Date(2019, time.January, 30, 0, 0, 0, 0, time.UTC)

CommitTime is the time returned by all calls to the .info endpoint.

Functions

func NewClientForServer

func NewClientForServer(s *Server) (*proxy.Client, func(), error)

NewClientForServer starts serving proxyMux locally. It returns a client to the server and a function to shut down the server.

func SetupTestClient

func SetupTestClient(t *testing.T, modules []*Module) (*proxy.Client, func())

SetupTestClient creates a fake module proxy for testing using the given test version information.

It returns a function for tearing down the proxy after the test is completed and a Client for interacting with the test proxy.

Types

type Module

type Module struct {
	ModulePath string
	Version    string
	Files      map[string]string
	NotCached  bool // if true, behaves like it's uncached
	// contains filtered or unexported fields
}

Module represents a module version used by the proxy server.

func FindModule

func FindModule(mods []*Module, path, version string) *Module

FindModule returns the module in mods with the given path and version, or nil if there isn't one. An empty version argument matches any version.

func LoadTestModules

func LoadTestModules(dir string) []*Module

LoadTestModules reads the modules in the given directory. Each file in that directory with a .txtar extension should be named "path@version" and should be in txtar format (golang.org/x/tools/txtar). The path part of the filename will be preceded by "example.com/" and colons will be replaced by slashes to form a full module path. The file contents are used verbatim except that some variables beginning with "$" are substituted with predefined strings.

LoadTestModules panics if there is an error reading any of the files.

func (*Module) AddFile

func (m *Module) AddFile(filename, contents string) *Module

AddFile returns a copy of m with an additional file. It panics if the filename is already present.

func (*Module) ChangePath

func (m *Module) ChangePath(modulePath string) *Module

ChangePath returns a copy of m with a different module path.

func (*Module) ChangeVersion

func (m *Module) ChangeVersion(version string) *Module

ChangeVersion returns a copy of m with a different version.

func (*Module) DeleteFile

func (m *Module) DeleteFile(filename string) *Module

DeleteFile returns a copy of m with filename removed. It panics if filename is not present.

func (*Module) ReplaceFile

func (m *Module) ReplaceFile(filename, contents string) *Module

ReplaceFile returns a copy of m with different contents for filename. It panics if filename is not present.

type Server

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

Server represents a proxy server containing the specified modules.

func NewServer

func NewServer(modules []*Module) *Server

NewServer returns a proxy Server that serves the provided modules.

func (*Server) AddModule

func (s *Server) AddModule(m *Module)

AddModule adds an additional module to the server.

func (*Server) AddModuleNoVersions

func (s *Server) AddModuleNoVersions(m *Module)

AddModuleNoLatest adds a module to the server, but the @v/list endpoint will return nothing and @latest endpoint will serve a 410. For testing the unusual case where a module exists but there is no version information.

func (*Server) AddRoute

func (s *Server) AddRoute(route string, fn func(w http.ResponseWriter, r *http.Request))

AddRoute adds an additional handler to the server.

func (*Server) ZipRequests

func (s *Server) ZipRequests() int

Jump to

Keyboard shortcuts

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