testutils

package
v0.0.0-...-9b0ccd2 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2025 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareObjects

func CompareObjects(actual interface{}, expected interface{}) error

CompareObjects checks equality of 2 objects and returns a formatted error on failure. If the object types have unexported fields, a custom marshaler is required to be defined.

func FailOnError

func FailOnError(t *testing.T, err error)

FailOnError logs the error and terminates the test immediately

func FailOnNil

func FailOnNil(t *testing.T, obj interface{})

FailOnNil terminates the test immediately if the argument is nil and logs the reason

func GenerateUPIRequest

func GenerateUPIRequest(n int, m int) *upiv1.PredictValuesRequest

func MakeTestMisisonControlResponse

func MakeTestMisisonControlResponse() mchttp.Response

MakeTestMisisonControlResponse makes a success response with a dummy json body for testing

func MakeTestRequest

func MakeTestRequest(
	t *testing.T,
	httpRequestModifier func(*http.Request),
) *http.Request

MakeTestRequest creates a dummy request for testing

func NopHTTPRequestModifier

func NopHTTPRequestModifier(_ *http.Request)

NopHTTPRequestModifier makes no modification to the input request

func ReadFile

func ReadFile(filepath string) ([]byte, error)

ReadFile reads a file and returns the byte contents

func RunTestUPIHttpServer

func RunTestUPIHttpServer(port int)

func RunTestUPIServer

func RunTestUPIServer(port int) *grpc.Server

Types

type GrpcTestServer

type GrpcTestServer struct {
}

func (*GrpcTestServer) PredictValues

type HTTPTestServer

type HTTPTestServer struct {
}

func (*HTTPTestServer) ServeHTTP

func (h *HTTPTestServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

type MemorySink

type MemorySink struct {
	*bytes.Buffer
}

MemorySink implements zap.Sink by writing all messages to a buffer.

func NewLoggerWithMemorySink

func NewLoggerWithMemorySink() (*zap.SugaredLogger, *MemorySink, error)

NewLoggerWithMemorySink creates a new zap logger with a memory sink, to which all output is redirected. Calling sink.String() / sink.Bytes() ... will give access to its contents.

func (*MemorySink) Close

func (s *MemorySink) Close() error

Close is a nop method to satisfy the zap.Sink interface

func (*MemorySink) Sync

func (s *MemorySink) Sync() error

Sync is a nop method to satisfy the zap.Sink interface

Jump to

Keyboard shortcuts

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