mocka

package module
v0.0.0-...-c04d48c Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2022 License: MIT Imports: 10 Imported by: 0

README

mocka

A tiny Go library to create, start, stop and remove dummy services, e.g. for integration tests.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Service

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

A Service takes care of creating the source file and building the executable. It can start the executable as well.

func NewConsoleService

func NewConsoleService(exitCode int) *Service

NewConsoleService creates a new *Service containing a console application which always exits with the supplied exit code.

func NewWebAppService

func NewWebAppService(port, statusCode int, statusMessage string) *Service

NewWebAppService creates a new *Service containing a web application listening on port, returning statusCode and statusMessage in every HTTP response.

func (*Service) Build

func (s *Service) Build() error

Build actually builds the application into an executable.

func (*Service) CopyExe

func (s *Service) CopyExe(name string) error

CopyExe copies the executable into a file.

func (*Service) CopySource

func (s *Service) CopySource(file string) error

CopySource creates a named file containing the source code of the application.

func (*Service) GetExePath

func (s *Service) GetExePath() string

GetExePath returns the path to the built executable. If it has not been built yet, GetExePath returns an empty string.

func (*Service) Start

func (s *Service) Start(ctx context.Context) error

Start starts the built executable. If the supplied context is nil, *Service uses an internal context which can be cancelled by calling Stop(). Otherwise you have to cancel the supplied context yourself.

func (*Service) Stop

func (s *Service) Stop()

Stop stops the built executable if it has been started with the internal context.

func (*Service) WriteExe

func (s *Service) WriteExe(w io.Writer) error

WriteExe copies the executable content into w.

func (*Service) WriteSource

func (s *Service) WriteSource(w io.Writer) error

WriteSource writes the source code of the application into w.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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