-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Extensions file
// file: extensions/0001.go
package mock_http_extensions
import (
"fmt"
"net/http"
"time"
)
func RequestTransformerFunc(*http.Request) *http.Request { return nil }
func ResponseTransformerFunc(*http.Response) *http.Response { return nil }
func ResponsePassesValidationFunc(req *http.Request, res *http.Response, tests struct {
HTTP *struct {
Status *int
Headers map[string][]string
Body any
}
Duration *time.Duration
}) bool {
var isOk bool
status := Unwrap[int](tests.HTTP.Status, -100)
if status != res.StatusCode {
fmt.Printf("ERROR: expected status %v, but got %v\n", status, res.StatusCode)
}
// TODO: Test body and headers
return isOk
}
func Unwrap[T any](optional *T, d T) T {
if optional == nil {
return d
}
return *optional
}Env
# 1 - fatal
# 2 - error
# 3 - warn
# 4 - info
# 5 - debug
LOG_LEVEL=5
PLUGINS_FILEPATH=./extensions/0001.go
Execution log
go run . http -o yaml -f ./examples/0001.yaml
WARN[0000] Loaded extension: ResponsePassesValidationFunc 0x1044dc5a0
WARN[0000] Loaded extension: RequestTransformerFunc 0x1044dc5a0
WARN[0000] Loaded extension: ResponseTransformerFunc 0x1044dc5a0
DEBU[0000] schema.LoadSchema
DEBU[0000] schema.Execute
DEBU[0000] schema.Consume
DEBU[0000] schema.Send
DEBU[0000] schema.(*Request).ParseURL
DEBU[0000] schema.(*Request).ParseURL https://api.datamuse.com/words?ml=ocean
DEBU[0000] schema.(*Request).HeaderMap
DEBU[0001] schema.Send request sent...
DEBU[0001] Response for: Datamuse - words related to `ocean`
DEBU[0001] schema.(*Request).ParseURL
DEBU[0001] schema.(*Request).ParseURL https://api.datamuse.com/words?ml=ocean
DEBU[0001] schema.BodyMarshalFunc application/json
WARN[0001] Running code for: ResponsePassesValidationFunc
WARN[0001] Running tests for: Datamuse - words related to `ocean`
ERROR: expected status 400, but got 200
For more details, check out the extensions directory and how it is used in main.go
Metadata
Metadata
Assignees
Labels
No labels