tf

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2024 License: BSD-2-Clause Imports: 15 Imported by: 0

Documentation

Overview

Package tf provides common test functions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func B64

func B64(t *testing.T, b []byte) string

B64 outputs base64-encodes a byte slice

func B64Dec

func B64Dec(t *testing.T, s string) []byte

B64Dec base64-decodes a string

func Different

func Different(t *testing.T, desc string, got, want any) bool

Different checks if a and b are not deeply equal, see reflect.DeepEqual(). An error is printed if a and b are equal. The output is then set to false.

func ECDSA

func ECDSA(t *testing.T) (pubID [sha256.Size]byte, pubDER []byte, pub crypto.PublicKey, priv *ecdsa.PrivateKey)

ECDSA outputs a new ECDSA public-key pair

func Ed25519

func Ed25519(t *testing.T) (pubID [sha256.Size]byte, pubDER []byte, pub crypto.PublicKey, priv *ed25519.PrivateKey)

Ed25519 outputs a new Ed25519 public-key pair

func Ed25519Sign

func Ed25519Sign(t *testing.T, priv *ed25519.PrivateKey, msg []byte) []byte

Ed25519Sign signs a message using Ed25519

func Equal

func Equal(t *testing.T, desc string, got, want any) bool

Equal checks if a and b are deeply equal, see reflect.DeepEqual(). An error is printed if a and b are not equal. The output is then set to false.

func Error

func Error(t *testing.T, desc string, err error) bool

Error checks if an error from a previous operation was expected by checking if desc starts with the string "valid". An error is printed if the value of err is unexpected. True is returned if err is non-nil or wrongly nil.

func MapOptions

func MapOptions(t *testing.T, usage string) map[byte]string

MapOptions extracts options from lines in a usage message that starts with:

<space><space>-<character>,<space>--<characters>:

func RSA

func RSA(t *testing.T, bits int) (pubID [sha256.Size]byte, pubDER []byte, pub crypto.PublicKey, priv *rsa.PrivateKey)

RSA outputs a new RSA public-key pair

func RSASign

func RSASign(t *testing.T, priv *rsa.PrivateKey, msg []byte) (sig []byte)

RSASign signs a message using RSA-PKCS1-V1_5 with SHA256

func ReplaceShortWithLong

func ReplaceShortWithLong(t *testing.T, usage, cmdLine string) (ret string)

ReplaceShortWithLong transforms a command-line string with short options to an equivalent one with long options, substituting from a usage message. The usage message must be formatted as described in MapOptions, see above.

Be warned: substitution is not be perfect, but it should be good enough to not cause headaches while catching most inconsistencies between usage messages and the parameters which are passed to a command's flag set.

Types

type Transport

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

Transport implements the http.RoundTripper interface for use in tests

func NewTransport

func NewTransport(t *testing.T, message [][]byte, status []int) Transport

NewTransport outputs a new test transport

func (Transport) Check

func (t Transport) Check()

Check reports errors if any items are left to be consumed

func (Transport) RoundTrip

func (t Transport) RoundTrip(_ *http.Request) (*http.Response, error)

RoundTrip tries to create a test response to an HTTP request. An error is created if a test response is not available.

Jump to

Keyboard shortcuts

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