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

testserver

package module
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 14 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArtifactServer

type ArtifactServer struct {
	*HTTPServer
}

ArtifactServer is an HTTP/S artifact server for testing purposes. It offers utilities to generate mock tarball artifacts to be served by the server.

func NewTempArtifactServer

func NewTempArtifactServer() (*ArtifactServer, error)

NewTempArtifactServer returns an ArtifactServer with a newly created temp dir as the artifact docroot.

func (*ArtifactServer) ArtifactFromDir added in v0.4.0

func (s *ArtifactServer) ArtifactFromDir(source, destination string) (string, error)

ArtifactFromDir creates a tar.gz artifact from the source directory into the destination dir and returns the artifact SHA256 checksum.

func (*ArtifactServer) ArtifactFromFiles

func (s *ArtifactServer) ArtifactFromFiles(files []File) (string, error)

ArtifactFromFiles creates a tar.gz artifact from the given files and returns the file name of the artifact.

func (*ArtifactServer) URLForFile

func (s *ArtifactServer) URLForFile(file string) (string, error)

URLForFile returns the URL the given file can be reached at or an error if the server has not been started.

type File

type File struct {
	Name string
	Body string
}

File holds the name and string contents of an artifact file.

type HTTPServer

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

HTTPServer is an HTTP/S server for testing purposes. It can serve files from the configured docroot and offers a lightweight middleware configuration option.

func NewHTTPServer

func NewHTTPServer(docroot string) *HTTPServer

NewHTTPServer returns a HTTPServer with the given docroot set.

func NewTempHTTPServer

func NewTempHTTPServer() (*HTTPServer, error)

NewTempHTTPServer returns a HTTPServer with a newly created temp dir as the docroot.

func (*HTTPServer) Root

func (s *HTTPServer) Root() string

Root returns the configured docroot of the HTTPServer.

func (*HTTPServer) Start

func (s *HTTPServer) Start()

Start starts the HTTPServer.

func (*HTTPServer) StartTLS

func (s *HTTPServer) StartTLS(cert, key, ca []byte, serverName string) error

StartTLS starts the TLS HTTPServer with the given TLS configuration.

func (*HTTPServer) Stop

func (s *HTTPServer) Stop()

Stop stops the HTTPServer, if started.

func (*HTTPServer) URL

func (s *HTTPServer) URL() string

URL returns the address the HTTPServer is listening at, if started.

func (*HTTPServer) WithMiddleware

func (s *HTTPServer) WithMiddleware(m func(handler http.Handler) http.Handler) *HTTPServer

WithMiddleware configures the middleware of the HTTPServer, this can for example be used to configure Basic Auth credentials. It should be called before starting the server, or requires a stop/start cycle.

Jump to

Keyboard shortcuts

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