testing

package
v0.0.0-...-b1a7a90 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

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 JQ

func JQ(filter string, input interface{}) (results []interface{}, err error)

JQ runs the given `jq` filter on the given object and returns the list of results. The returned slice will never be nil; if there are no results it will be empty.

func LocalhostCertificate

func LocalhostCertificate() tls.Certificate

LocalhostCertificate returns a self signed TLS certificate valid for the name `localhost` DNS name, for the `127.0.0.1` IPv4 address and for the `::1` IPv6 address.

A similar certificate can be generated with the following command:

openssl req \
-x509 \
-newkey rsa:4096 \
-nodes \
-keyout tls.key \
-out tls.crt \
-subj '/CN=localhost' \
-addext 'subjectAltName=DNS:localhost,IP:127.0.0.1,IP:::1' \
-days 1

func MakeClaims

func MakeClaims() jwt.MapClaims

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

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 MatchJQ

func MatchJQ(filter string, expected interface{}) types.GomegaMatcher

MatchJQ creates a matcher that checks that the all the results of applying a `jq` filter to the actual value is the given expected value.

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 RespondWithContent

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

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

func RespondWithJSON

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

RespondWithJSON responds with the given status code and JSON body.

func RespondWithObject

func RespondWithObject(object data.Object) http.HandlerFunc

RespondWithObject returns an HTTP handler that responds with a single object.

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