test_utils

package
v0.0.0-...-436d200 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2023 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Utility functions for testing net2/http2

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureListen

func EnsureListen(c *C, hostport string)

This checks to ensure a server is running on the specified host port. DO NOT USE IN PRODUCTION.

func GenerateCertWithCA

func GenerateCertWithCA(hostname string) ([]byte, []byte, []byte, error)

generate CA and certificate signed by generated CA. Returns CA's certificate, certificate, private key, error

func GenerateCertWithCAPrefs

func GenerateCertWithCAPrefs(
	hostname string, lookupIps bool, expiration time.Duration) ([]byte, []byte, []byte, error)

func GenerateSelfSignedCert

func GenerateSelfSignedCert(hostname string) ([]byte, []byte, error)

GenerateSelfSignedCert genereate self-signed certificate and returns public certificate in pem, private key in pem, error.

func PrivDerToPem

func PrivDerToPem(priv *rsa.PrivateKey) []byte

PrivDerToPem converts rsa private key from der to pem.

func PubDerToPem

func PubDerToPem(der []byte) []byte

PubDerToPem converts public key from der format to pem.

func RandomListenPort

func RandomListenPort(c *C) int

This returns a random port for unit testing. DO NOT USE IN PRODUCTION.

Types

type CustomHandler

type CustomHandler struct {
	Handler func(witer http.ResponseWriter, req *http.Request)
}

func (*CustomHandler) ServeHTTP

func (c *CustomHandler) ServeHTTP(
	writer http.ResponseWriter,
	req *http.Request)

type TestServer

type TestServer struct {
	*httptest.Server

	CloseChan chan bool
}

func SetupTestServer

func SetupTestServer(ssl bool) (*TestServer, string)

Create a dummy server for unittesting. DO NOT USE IN PRODUCTION.

Jump to

Keyboard shortcuts

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