testutil

package
v0.1.0-alpha.20260716 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package testutil provides helpers and utilities to make testing easier and less tedious.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ECDSACert

func ECDSACert(t *testing.T, tmpl *x509.Certificate) []byte

ECDSACert generates a self-signed ECDSA P-256 certificate from tmpl and returns its PEM encoding. The generated key is discarded; callers that need a matching key should use GenerateSelfSignedCert or GenerateMTLSCerts.

func GenerateMTLSCerts

func GenerateMTLSCerts(t *testing.T) (caFile, certFile, keyFile string)

GenerateMTLSCerts writes a self-signed ECDSA P-256 CA certificate plus a leaf certificate signed by that CA (with its matching key) to a fresh testing.T.TempDir and returns the three paths. The leaf advertises CN "localhost" with DNSNames=["localhost"]; both certificates are valid for one hour. Use this when a test needs the leaf to verify against the CA.

func GenerateSelfSignedCert

func GenerateSelfSignedCert(t *testing.T) (certFile, keyFile string)

GenerateSelfSignedCert writes a self-signed ECDSA P-256 certificate and its matching PKCS#1-style EC private key to a fresh testing.T.TempDir and returns the paths. The certificate is valid for one hour, advertises CN "localhost" with DNSNames=["localhost"], and is suitable for loading via crypto/tls.LoadX509KeyPair in server-auth scenarios.

func RSACert

func RSACert(t *testing.T, tmpl *x509.Certificate) []byte

RSACert generates a self-signed RSA-2048 certificate from tmpl and returns its PEM encoding. The generated key is discarded; callers that need a matching key should use GenerateSelfSignedCert or GenerateMTLSCerts.

func WriteFile

func WriteFile(t *testing.T, dir, name string, contents []byte) string

WriteFile writes contents to dir/name with mode 0600 and returns the full path. Any IO failure fails the test immediately. Callers typically pass testing.T.TempDir as dir so cleanup is automatic.

Types

This section is empty.

Jump to

Keyboard shortcuts

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