devtest

package
v0.0.0-...-45fb5ce Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2026 License: Apache-2.0 Imports: 19 Imported by: 1

README

Package cloudeng.io/webapp/devtest

import cloudeng.io/webapp/devtest

Package devtest provides utilities for the development and testing of web applications, including TLS certificate generation and management.

Functions

Func CertPoolForTesting
func CertPoolForTesting(pemFiles ...string) (*x509.CertPool, error)

CertPoolForTesting returns a new x509.CertPool containing the certs in the specified pem files. If no pem files are specified nil it will return the system cert pool. It is intended for testing purposes only.

Func NewSelfSignedCert
func NewSelfSignedCert(certFile, keyFile string, options ...SelfSignedOption) error

NewSelfSignedCert creates a self signed certificate. Default values for the supported options are:

  • an rsa 4096 bit private key will be generated and used.
  • "localhost" and "127.0.0.1" are used for the DNS and IP addresses included in the certificate.
  • certificates are valid from time.Now() and for 5 days.
  • the organization is 'cloudeng llc'.
Func NewSelfSignedCertUsingMkcert
func NewSelfSignedCertUsingMkcert(certFile, keyFile string, hosts ...string) error

NewSelfSignedCertUsingMkcert uses mkcert (https://github.com/FiloSottile/mkcert) to create certificates. If mkcert --install has been run then these certificates will be trusted by the browser and other local applications.

Types

Type JSServer
type JSServer struct {
	// contains filtered or unexported fields
}

JSServer provides a http.Handler for serving JavaScript files using a simple template that executes each file in turn. An optional TypescriptSources can be provided to compile TypeScript files before generating the http response.

Functions
func NewJSServer(title string, ts *TypescriptSources, jsScripts ...string) *JSServer
Methods
func (jss *JSServer) ServeJS(rw http.ResponseWriter, r *http.Request)

ServeJS handles HTTP requests for serving a series of Javascript files.

Type SelfSignedOption
type SelfSignedOption func(ssc *selfSignedCertOptions)

SelfSignedOption represents an option to NewSelfSignedCert.

Functions
func CertAllIPAddresses() SelfSignedOption

CertIPAddresses specifies that all local IPs be used in the generated certificate.

func CertDNSHosts(hosts ...string) SelfSignedOption

CertDNSHosts specifies the set of dns host names to use in the generated certificate.

func CertIPAddresses(ips ...string) SelfSignedOption

CertIPAddresses specifies the set of ip addresses to use in the generated certificate.

func CertOrganizations(orgs ...string) SelfSignedOption

CertOrganizations specifies that the organization to be used in the generated certificate.

func CertPrivateKey(key crypto.PrivateKey) SelfSignedOption

CertPrivateKey specifies the private key to use for the certificate.

Type TypescriptOption
type TypescriptOption func(o *typescriptOptions)

TypescriptOption represents an option to NewTypescriptSources.

Functions
func WithTypescriptCompiler(compiler string) TypescriptOption

WithTypescriptCompiler sets the TypeScript compiler to use. The default is "tsc".

func WithTypescriptTarget(target string) TypescriptOption

WithTypescriptTarget sets the target version for the TypeScript compiler. The default is "es2015".

Type TypescriptSources
type TypescriptSources struct {
	// contains filtered or unexported fields
}

TypescriptSources represents a collection of TypeScript source files that can be compiled using the TypeScript compiler.

Functions
func NewTypescriptSources(opts ...TypescriptOption) *TypescriptSources

NewTypescriptSources creates a new instance of TypescriptSources

Methods
func (ts *TypescriptSources) Compile(ctx context.Context) error

Compile compiles the TypeScript sources that have been modified since it was last run.

func (ts *TypescriptSources) SetDirAndFiles(dir string, files ...string)

SetFiles sets the directory and files for the TypeScript sources. The output will be in the same directory, 'dir', as the input files.

Documentation

Overview

Package devtest provides utilities for the development and testing of web applications, including TLS certificate generation and management.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CertPoolForTesting

func CertPoolForTesting(pemFiles ...string) (*x509.CertPool, error)

CertPoolForTesting returns a new x509.CertPool containing the certs in the specified pem files. If no pem files are specified nil it will return the system cert pool. It is intended for testing purposes only.

func NewSelfSignedCert

func NewSelfSignedCert(certFile, keyFile string, options ...SelfSignedOption) error

NewSelfSignedCert creates a self signed certificate. Default values for the supported options are:

  • an rsa 4096 bit private key will be generated and used.
  • "localhost" and "127.0.0.1" are used for the DNS and IP addresses included in the certificate.
  • certificates are valid from time.Now() and for 5 days.
  • the organization is 'cloudeng llc'.

func NewSelfSignedCertUsingMkcert

func NewSelfSignedCertUsingMkcert(certFile, keyFile string, hosts ...string) error

NewSelfSignedCertUsingMkcert uses mkcert (https://github.com/FiloSottile/mkcert) to create certificates. If mkcert --install has been run then these certificates will be trusted by the browser and other local applications.

Types

type JSServer

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

JSServer provides a http.Handler for serving JavaScript files using a simple template that executes each file in turn. An optional TypescriptSources can be provided to compile TypeScript files before generating the http response.

func NewJSServer

func NewJSServer(title string, ts *TypescriptSources, jsScripts ...string) *JSServer

func (*JSServer) ServeJS

func (jss *JSServer) ServeJS(rw http.ResponseWriter, r *http.Request)

ServeJS handles HTTP requests for serving a series of Javascript files.

type SelfSignedOption

type SelfSignedOption func(ssc *selfSignedCertOptions)

SelfSignedOption represents an option to NewSelfSignedCert.

func CertAllIPAddresses

func CertAllIPAddresses() SelfSignedOption

CertIPAddresses specifies that all local IPs be used in the generated certificate.

func CertDNSHosts

func CertDNSHosts(hosts ...string) SelfSignedOption

CertDNSHosts specifies the set of dns host names to use in the generated certificate.

func CertIPAddresses

func CertIPAddresses(ips ...string) SelfSignedOption

CertIPAddresses specifies the set of ip addresses to use in the generated certificate.

func CertOrganizations

func CertOrganizations(orgs ...string) SelfSignedOption

CertOrganizations specifies that the organization to be used in the generated certificate.

func CertPrivateKey

func CertPrivateKey(key crypto.PrivateKey) SelfSignedOption

CertPrivateKey specifies the private key to use for the certificate.

type TypescriptOption

type TypescriptOption func(o *typescriptOptions)

TypescriptOption represents an option to NewTypescriptSources.

func WithTypescriptCompiler

func WithTypescriptCompiler(compiler string) TypescriptOption

WithTypescriptCompiler sets the TypeScript compiler to use. The default is "tsc".

func WithTypescriptTarget

func WithTypescriptTarget(target string) TypescriptOption

WithTypescriptTarget sets the target version for the TypeScript compiler. The default is "es2015".

type TypescriptSources

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

TypescriptSources represents a collection of TypeScript source files that can be compiled using the TypeScript compiler.

func NewTypescriptSources

func NewTypescriptSources(opts ...TypescriptOption) *TypescriptSources

NewTypescriptSources creates a new instance of TypescriptSources

func (*TypescriptSources) Compile

func (ts *TypescriptSources) Compile(ctx context.Context) error

Compile compiles the TypeScript sources that have been modified since it was last run.

func (*TypescriptSources) SetDirAndFiles

func (ts *TypescriptSources) SetDirAndFiles(dir string, files ...string)

SetFiles sets the directory and files for the TypeScript sources. The output will be in the same directory, 'dir', as the input files.

Directories

Path Synopsis
Package chromedputil provides utility functions for working with the Chrome DevTools Protocol via github.com/chromedp.
Package chromedputil provides utility functions for working with the Chrome DevTools Protocol via github.com/chromedp.

Jump to

Keyboard shortcuts

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