Documentation ¶
Index ¶
- func CombineTransports(transports ...http.RoundTripper) http.RoundTripper
- func DefaultJWKS() []byte
- func ErrorTransport(err error) http.RoundTripper
- func EvaluateTemplate(source string, args ...interface{}) string
- func JQ(filter string, input interface{}) (results []interface{}, err error)
- func JSONTransport(code int, body string) http.RoundTripper
- func LocalhostCertificate() tls.Certificate
- func MakeClaims() jwt.MapClaims
- func MakeTCPH2CServer() *ghttp.Server
- func MakeTCPServer() *ghttp.Server
- func MakeTCPTLSServer() (server *ghttp.Server, ca string)
- func MakeTokenObject(claims jwt.MapClaims) *jwt.Token
- func MakeTokenString(typ string, life time.Duration) string
- func MakeUnixH2CServer() (server *ghttp.Server, socket string)
- func MakeUnixServer() (server *ghttp.Server, socket string)
- func MakeUnixTLSServer() (server *ghttp.Server, ca, socket string)
- func MatchJQ(filter string, expected interface{}) types.GomegaMatcher
- func MatchJSONTemplate(template string, args ...interface{}) types.GomegaMatcher
- func MatchLine(regexp string, args ...interface{}) OmegaMatcher
- func RemoveLeadingTabs(s string) string
- func RespondWithAccessAndRefreshTokens(accessToken, refreshToken string) http.HandlerFunc
- func RespondWithAccessToken(accessToken string) http.HandlerFunc
- func RespondWithContent(status int, contentType, body string) http.HandlerFunc
- func RespondWithCookie(name, value string) http.HandlerFunc
- func RespondWithJSON(status int, body string) http.HandlerFunc
- func RespondWithJSONTemplate(status int, source string, args ...interface{}) http.HandlerFunc
- func RespondWithPatchedJSON(status int, body string, patch string) http.HandlerFunc
- func RespondWithTokenError(err, description string) http.HandlerFunc
- func TextTransport(code int, body string) http.RoundTripper
- func VerifyCookie(name, value string) http.HandlerFunc
- func VerifyJQ(filter string, expected interface{}) http.HandlerFunc
- type Database
- type DatabaseServer
- type MetricsServer
- type TransportFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CombineTransports ¶
func CombineTransports(transports ...http.RoundTripper) http.RoundTripper
CombineTransports returns a transport that delegates to the given array of transports, in the given order. First request will go to the first transport, sceond request to the second transport, so on.
func DefaultJWKS ¶
func DefaultJWKS() []byte
DefaultJWKS generates the JSON web key set used for tests.
func ErrorTransport ¶
func ErrorTransport(err error) http.RoundTripper
ErrorTransport creates a transport that always returns the given error.
func EvaluateTemplate ¶
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 JQ ¶
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 JSONTransport ¶
func JSONTransport(code int, body string) http.RoundTripper
JSONTransport creates a transport that always returns the given status code and JSON body.
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 MakeTCPH2CServer ¶
MakeTCPH2CServer creates a test server that supports HTTP/2 without TLS, configured so that it sends log messages to the Ginkgo writer.
func MakeTCPServer ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 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 MatchJSONTemplate ¶
func MatchJSONTemplate(template string, args ...interface{}) types.GomegaMatcher
MatchJSONTemplate succeeds if actual is a string or stringer of JSON that matches the result of evaluating the given template with the given arguments.
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 ¶
RemoveLeadingTabs removes the leading tabs from the lines of the given string.
func RespondWithAccessAndRefreshTokens ¶
func RespondWithAccessAndRefreshTokens(accessToken, refreshToken string) http.HandlerFunc
func RespondWithAccessToken ¶
func RespondWithAccessToken(accessToken string) http.HandlerFunc
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 RespondWithPatchedJSON ¶
func RespondWithPatchedJSON(status int, body string, patch string) http.HandlerFunc
RespondWithPatchedJSON responds with the given status code and the result of patching the given JSON with the given patch.
func RespondWithTokenError ¶
func RespondWithTokenError(err, description string) http.HandlerFunc
func TextTransport ¶
func TextTransport(code int, body string) http.RoundTripper
TextTransport creates a transport that always returns the given status code and plan text body.
func VerifyCookie ¶
func VerifyCookie(name, value string) http.HandlerFunc
VerifyCookie checks that the request contains a cookie with the given name and value.
func VerifyJQ ¶
func VerifyJQ(filter string, expected interface{}) http.HandlerFunc
VerifyJQ verifies that the result of applying the given `jq` filter to the request body matches the given expected value.
Types ¶
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database is a PostgreSQL database.
func (*Database) MakeHandle ¶
MakeHandle creates a new database handle for this database.
type DatabaseServer ¶
type DatabaseServer struct {
// contains filtered or unexported fields
}
DatabaseServer knows how to start a PostgreSQL database server inside a container, and how to create databases to be used for tests.
func MakeDatabaseServer ¶
func MakeDatabaseServer() *DatabaseServer
MakeDatabaseServer creates a new database server.
func (*DatabaseServer) MakeDatabase ¶
func (s *DatabaseServer) MakeDatabase() *Database
MakeDatabase creates a new database.
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.
type TransportFunc ¶
TransportFunc is a function that implements the http.RoundTripper interface. This is intended to siplify writing tests that require custom round trippers because it doesn't require a new type. For example, to create a round tripper that always returns an error:
transport := testing.TransportFunc(func (*http.Request) (*http.Response, error) { return nil, errors.New("my error") })