testutil

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package testutil is testing helpers for the Landns.

Index

Constants

View Source
const (
	// PortMin is minimum port number for FindEmptyPort.
	PortMin = 49152

	// PortMax is maximum port number for FindEmptyPort.
	PortMax = 65535
)

Variables

This section is empty.

Functions

func FindEmptyPort

func FindEmptyPort() int

FindEmptyPort is find unused TCP port.

func StartServer

func StartServer(ctx context.Context, t SimpleTB, debugMode bool) (client.Client, *net.UDPAddr)

StartServer is make landns.Server and start it.

Types

type DNSServer

type DNSServer struct {
	Addr *net.UDPAddr
}

DNSServer is tester for DNS blackbox test.

func StartDNSServer

func StartDNSServer(ctx context.Context, t SimpleTB, resolver landns.Resolver) DNSServer

StartDNSServer is make dns.Server and start it.

func (DNSServer) Assert

func (d DNSServer) Assert(t SimpleTB, q dns.Question, expect ...string)

Assert is assertion tester for dns message exchange.

type DummyResolver

type DummyResolver struct {
	Error     bool
	Recursion bool
}

DummyResolver is stub of landns.Resolver.

func (DummyResolver) Close

func (dr DummyResolver) Close() error

Close is nothing to do.

func (DummyResolver) RecursionAvailable

func (dr DummyResolver) RecursionAvailable() bool

RecursionAvailable is returns value of DummyResolver.Recursion.

func (DummyResolver) Resolve

func (dr DummyResolver) Resolve(w landns.ResponseWriter, r landns.Request) error

Resolve is returns error if DummyResolver.Error is true, otherwise nothing to do.

type DummyResponseWriter

type DummyResponseWriter struct {
	Records       []landns.Record
	Authoritative bool
}

DummyResponseWriter is array stub of landns.ResponseWriter.

func NewDummyResponseWriter

func NewDummyResponseWriter() *DummyResponseWriter

NewDummyResponseWriter is constructor of DummyResponseWriter.

func (*DummyResponseWriter) Add

func (rw *DummyResponseWriter) Add(r landns.Record) error

Add is adding record into DummyResponseWriter.Records.

func (*DummyResponseWriter) IsAuthoritative

func (rw *DummyResponseWriter) IsAuthoritative() bool

IsAuthoritative is returns value of DummyResponseWriter.Authoritative.

func (*DummyResponseWriter) SetNoAuthoritative

func (rw *DummyResponseWriter) SetNoAuthoritative()

SetNoAuthoritative is set value to DummyResponseWriter.Authoritative.

type DummyTB

type DummyTB struct {
	Errors []string
	Fatals []string
}

DummyTB is the tester for assert functions.

func (*DummyTB) AssertErrors

func (t *DummyTB) AssertErrors(tb SimpleTB, expect ...string)

AssertErrors is test error logs.

func (*DummyTB) AssertFatals

func (t *DummyTB) AssertFatals(tb SimpleTB, expect ...string)

AssertFatals is test fatal logs.

func (*DummyTB) Errorf

func (t *DummyTB) Errorf(format string, data ...interface{})

Errorf is error message recorder.

func (*DummyTB) Failed

func (t *DummyTB) Failed() bool

Failed is reports test has failed.

func (*DummyTB) Fatalf

func (t *DummyTB) Fatalf(format string, data ...interface{})

Fatalf is fatal error message recorder.

func (*DummyTB) Helper

func (t *DummyTB) Helper()

Helper is dummy function.

type EmptyResponseWriter

type EmptyResponseWriter struct{}

EmptyResponseWriter is empty stub of landns.ResponseWriter.

func (EmptyResponseWriter) Add

func (rw EmptyResponseWriter) Add(r landns.Record) error

Add is nothing to do.

func (EmptyResponseWriter) IsAuthoritative

func (rw EmptyResponseWriter) IsAuthoritative() bool

IsAuthoritative is always returns true.

func (EmptyResponseWriter) SetNoAuthoritative

func (rw EmptyResponseWriter) SetNoAuthoritative()

SetNoAuthoritative is nothing to do.

type HTTPResponse

type HTTPResponse struct {
	Method      string
	Path        string
	RequestBody string
	Status      int
	Body        string
}

HTTPResponse is response type from HTTPServer.

func (HTTPResponse) Assert

func (h HTTPResponse) Assert(t SimpleTB, status int, body string)

Assert is assertion test to HTTP response.

type HTTPServer

type HTTPServer struct {
	URL *url.URL
}

HTTPServer is tester for HTTP blackbox test.

func StartHTTPServer

func StartHTTPServer(ctx context.Context, t SimpleTB, handler http.Handler) HTTPServer

StartHTTPServer is make http.Server and start it.

func (HTTPServer) Do

func (h HTTPServer) Do(t SimpleTB, method, path, body string) (r HTTPResponse)

Do is do HTTP request to server.

type Metrics

type Metrics []MetricsEntry

Metrics is response data from MetricsServer.

func ParseMetrics

func ParseMetrics(str string) (Metrics, error)

ParseMetrics is parser for Metrics.

func (Metrics) Assert

func (ms Metrics) Assert(t SimpleTB, name string, labels MetricsLabels, value float64)

Assert is assertion test for Metrics data.

type MetricsEntry

type MetricsEntry struct {
	Name   string
	Labels MetricsLabels
	Value  float64
}

MetricsEntry is one entry of Metrics.

type MetricsLabels

type MetricsLabels map[string]string

MetricsLabels is labels for MetricsEntry.

func ParseMetricsLabels

func ParseMetricsLabels(str string) MetricsLabels

ParseMetricsLabels is parser to MetricsLabels.

func (MetricsLabels) String

func (l MetricsLabels) String() string

String is human readable string getter.

type MetricsServer

type MetricsServer struct {
	Metrics    *landns.Metrics
	HTTPServer HTTPServer
}

MetricsServer is tester for Metrics blackbox test.

func StartMetricsServer

func StartMetricsServer(ctx context.Context, t SimpleTB, namespace string) MetricsServer

StartMetricsServer is make metrics server and start it.

func (MetricsServer) Get

func (s MetricsServer) Get(t SimpleTB) Metrics

Get is get Metrics from MetricsServer.

type SimpleTB

type SimpleTB interface {
	Helper()
	Errorf(string, ...interface{})
	Fatalf(string, ...interface{})
	Failed() bool
}

SimpleTB is the interface to testing.T, testing.B and DummyTB.

Jump to

Keyboard shortcuts

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