testing

package
v0.1.175 Latest Latest
Warning

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

Go to latest
Published: May 6, 2021 License: Apache-2.0 Imports: 25 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultJWKS

func DefaultJWKS() []byte

DefaultJWKS generates the JSON web key set used for tests.

func EvaluateTemplate

func EvaluateTemplate(source string, args ...interface{}) string

EvaluateTemplate generates a string from the given templlate source and name value pairs. For example the following code:

EvaluateTemplate(
	`{
		"access_token": "{{ .AccessToken }}"
		"refresh_token": "{{ .RefreshToken }}"
	}`,
	"AccessToken", "myaccesstoken",
	"RefreshToken", "myrefreshtoken",
)

Will generate the following string:

{
	"access_token": "myaccesstoken"
	"access_token": "myrefreshtoken"
}

To simplify embeding of the templates in Go source the function also removes the leading tabs from the generated text.

func MakeClaims

func MakeClaims() jwt.MapClaims

MakeClaims generates a default set of claims to be used to issue a token.

func MakeTCPH2CServer

func MakeTCPH2CServer() *ghttp.Server

MakeTCPH2CServer creates a test server that supports HTTP/2 without TLS, configured so that it sends log messages to the Ginkgo writer.

func MakeTCPServer

func MakeTCPServer() *ghttp.Server

MakeTCPServer creates a test server that listens in a TCP socket and configured so that it sends log messages to the Ginkgo writer.

func MakeTCPTLSServer

func MakeTCPTLSServer() (server *ghttp.Server, ca string)

MakeTCPTLSServer creates a test server configured so that it sends log messages to the Ginkgo writer. It returns the created server and the name of a temporary file that contains the CA certificate that the client should trust in order to connect to the server. It is the responsibility of the caller to delete this temporary file when it is no longer needed.

func MakeTokenObject

func MakeTokenObject(claims jwt.MapClaims) *jwt.Token

MakeTokenObject generates a token with the claims resulting from merging the default claims and the claims explicitly given.

func MakeTokenString

func MakeTokenString(typ string, life time.Duration) string

MakeTokenString generates a token issued by the default OpenID server and with the given type and with the given life. If the life is zero the token will never expire. If the life is positive the token will be valid, and expire after that time. If the life is negative the token will be already expired that time ago.

func MakeUnixH2CServer

func MakeUnixH2CServer() (server *ghttp.Server, socket string)

MakeUnixH2cServer creates a test server that listens in a Unix socket and supports HTTP/2 without TLS, configured so that it sends log messages to the Ginkgo writer. It returns the created server and name of a temporary file containing the Unix socket. This file will be in a temporary directory, and the caller is resposible for removing the directory once it is no longer needed.

func MakeUnixServer

func MakeUnixServer() (server *ghttp.Server, socket string)

MakeUnixServer creates a test server that listens in a Unix socket and configured so that it sends log messages to the Ginkgo writer. It returns the created server and name of a temporary file containing the Unix socket. This file will be in a temporary directory, and the caller is resposible for removing the directory once it is no longer needed.

func MakeUnixTLSServer

func MakeUnixTLSServer() (server *ghttp.Server, ca, socket string)

MakeUnixTLSServer creates a test server that listens in a Unix socket and configured so that it sends log messages to the Ginkgo writer. It returns the created server, the name of a temporary file that contains the CA certificate that the client should trust in order to connect to the server and the name of a directory containing the Unix sockets. This file will be in a temporary directory. It is the responsibility of the caller to remove these temporary directories and files.

func MatchLine

func MatchLine(regexp string, args ...interface{}) OmegaMatcher

MatchLine succeeds if actual is an slice of strings that contains at least one items that matches the passed regular expression.

func RemoveLeadingTabs

func RemoveLeadingTabs(s string) string

RemoveLeadingTabs removes the leading tabs from the lines of the given string.

func RespondWithContent

func RespondWithContent(status int, contentType, body string) http.HandlerFunc

RespondeWithContent responds with the given status code, content type and body.

func RespondWithCookie

func RespondWithCookie(name, value string) http.HandlerFunc

RespondWithCookie responds to the request adding a cookie with the given name and value.

func RespondWithJSON

func RespondWithJSON(status int, body string) http.HandlerFunc

RespondWithJSON responds with the given status code and JSON body.

func RespondWithJSONTemplate

func RespondWithJSONTemplate(status int, source string, args ...interface{}) http.HandlerFunc

RespondWithJSONTemplate responds with the given status code and with a JSON body that is generated from the given template and arguments. See the EvaluateTemplate function for details on how the template and the arguments are combined.

func RespondWithTokenError

func RespondWithTokenError(err, description string) http.HandlerFunc

func RespondWithTokens added in v0.1.167

func RespondWithTokens(accessToken, refreshToken string) http.HandlerFunc

func VerifyCookie

func VerifyCookie(name, value string) http.HandlerFunc

VerifyCookie checks that the request contains a cookie with the given name and value.

Types

type MetricsServer

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

MetricsServer is an HTTP server configured to return Prometheus metrics. Don't create objects of this type directly, use the MakeMetricsServer function instead.

func NewMetricsServer

func NewMetricsServer() *MetricsServer

NewMetricsServer creates a metrics server.

func (*MetricsServer) Close

func (s *MetricsServer) Close()

Close stops the server and releases the resources it uses.

func (*MetricsServer) Metrics

func (s *MetricsServer) Metrics() []string

Metrics returns an array of strings containing the metrics available in this server. Each item in this array is a line in the Prometheus exposition format. This is intended to be used together with the MatchLine matcher.

func (*MetricsServer) Registry

func (s *MetricsServer) Registry() prometheus.Registerer

Registry returns the registry that should be used to register metrics for this server.

Jump to

Keyboard shortcuts

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