test

package
v0.0.0-...-d0ebcda Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2024 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	DefaultTracer = new(defaultTracer)
)
View Source
var (
	Dispatcher = new(testDispatch)
)

Functions

func Deserialize

func Deserialize[E ErrorHandler, T any](gotBody, wantBody io.Reader, t *testing.T) (gotT, wantT T, success bool)

func DispatchName

func DispatchName(t any) string
Example
fmt.Printf("test: DispatchName() -> %v\n", DispatchName(nil))

a := NewAgent("agent-test")
fmt.Printf("test: DispatchName() -> %v\n", DispatchName(a))

t := messaging.NewTicker("ticker-test", 100)
fmt.Printf("test: DispatchName() -> %v\n", DispatchName(t))

c := messaging.NewChannel("channel-test", false)
fmt.Printf("test: DispatchName() -> %v\n", DispatchName(c))

m := messaging.NewControlMessage("", "", "event-test")
fmt.Printf("test: DispatchName() -> %v\n", DispatchName(m))

fmt.Printf("test: DispatchName() -> %v\n", DispatchName(core.StatusNotFound()))

r := new(http.Response)
fmt.Printf("test: DispatchName() -> %v\n", DispatchName(r))
Output:

test: DispatchName() -> <nil>
test: DispatchName() -> agent-test
test: DispatchName() -> ticker-test
test: DispatchName() -> channel-test
test: DispatchName() -> event-test
test: DispatchName() -> Not Found
test: DispatchName() -> *http.Response

func NewAgent

func NewAgent(uri string) messaging.OpsAgent
Example
a := NewAgent("urn:any")
if _, ok := any(a).(messaging.Agent); ok {
	fmt.Printf("test: opsAgent() -> ok\n")
} else {
	fmt.Printf("test: opsAgent() -> fail\n")
}
Output:

test: opsAgent() -> ok

func NewAgentWithChannel

func NewAgentWithChannel(uri string, ch *messaging.Channel) messaging.OpsAgent

func NewRequest

func NewRequest(uri any) (*http.Request, *core.Status)

func NewRequestTest

func NewRequestTest(uri any, t *testing.T) *http.Request

func NewResponseTest

func NewResponseTest(uri any, t *testing.T) *http.Response

NewResponseTest - used from test packages

func ReadContent

func ReadContent(rawHttp []byte) (*bytes.Buffer, error)

func WriteResponse

func WriteResponse(url string, resp *http.Response) *core.Status
Example
package main

import (
	"fmt"
	"github.com/behavioral-ai/core/httpx"
)

const (
	testInputResponse  = "file://[cwd]/test/test-response.txt"
	testOutputResponse = "file://[cwd]/test/test-response-2.txt"
)

func _ExampleWriteStatusLine() {
	resp, status := httpx.NewResponseFromUri(testInputResponse)
	line := fmt.Sprintf("%v %v\n", resp.Proto, resp.Status)
	fmt.Printf("test: NewResponseFromUri() [status:%v] [%v]\n", status, line)

	
Output:

test: NewResponseFromUri() [status:OK] [HTTP/1.1 200 OK]
test: WriteResponse("file://[cwd]/test/test-response.txt") -> [status:OK]

Types

type ErrorHandler

type ErrorHandler interface {
	Handle(s *core.Status, t *testing.T, target string) *core.Status
}

ErrorHandler - error handler interface

type FileList

type FileList struct {
	Dir, Req, Resp string
}

FileList - note, req file name needs to have an extension

Example
fi := FileList{
	Dir:  "/test",
	Req:  "test-req.txt",
	Resp: "",
}

fmt.Printf("test: FileList() -> [req:%v] [resp:%v]\n", fi.RequestPath(), fi.ResponsePath())
Output:

test: FileList() -> [req:/test/test-req.txt] [resp:/test/test-req-resp.txt]

func (FileList) NewRequest

func (f FileList) NewRequest(req *http.Request) (*http.Request, *core.Status)

func (FileList) NewUrl

func (f FileList) NewUrl(req *http.Request) string

func (FileList) RequestPath

func (f FileList) RequestPath() string

func (FileList) ResponsePath

func (f FileList) ResponsePath() string

type Notifier

type Notifier interface {
	messaging.Notifier
	Status() *core.Status
	Reset()
}

func NewNotifier

func NewNotifier() Notifier
Example
n := NewNotifier()

n.Notify(core.StatusNotFound())
fmt.Printf("test: NewNotifier() -> [status:%v]\n", n.Status())

n.Reset()
n.Notify(core.StatusNoContent())
fmt.Printf("test: NewNotifier() -> [status:%v]\n", n.Status())
Output:

test: NewNotifier() -> [status:Not Found]
test: NewNotifier() -> [status:No Content]

type Output

type Output struct{}

Output - standard output error handler

func (Output) Handle

func (h Output) Handle(s *core.Status, t *testing.T, target string) *core.Status

Handle - output error handler

Jump to

Keyboard shortcuts

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