testutil

package
v1.0.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func BeRequest

func BeRequest[E ~string | ~[]byte | *http.Request](e E) testx.Matcher[*http.Request]

func NewHTTPServer

func NewHTTPServer(h http.Handler) *httptest.Server

NewHTTPServer is httptest.NewServer for handlers that need a real listener (Client.Do, TLS, etc.).

func ServeHandler

func ServeHandler(h http.Handler, req *http.Request) *httptest.ResponseRecorder

ServeHandler executes h against req with httptest.NewRecorder and returns the recorder.

func UnifyRequest

func UnifyRequest[E ~string | ~[]byte | *http.Request](req E) string
Example
package main

import (
	"bytes"
	"fmt"
	"net/http"
	"net/url"
	"strconv"

	"github.com/xoctopus/httpx/internal/testutil"
)

func main() {
	body := `{"k1":100,"k2":"200"}`

	req, _ := http.NewRequest(
		"POST",
		"/users/1?k1=v1&k2=v2",
		bytes.NewBufferString(body),
	)
	req.Header.Set("content-type", "applicaiton/json")
	req.Header.Set("content-length", strconv.Itoa(len(body)))
	req.Header.Set("user-agent", "goland")
	req.URL.RawQuery = (url.Values{
		"k1": []string{"1"},
		"k2": []string{"1", "2", "3"},
	}).Encode()

	fmt.Println(testutil.UnifyRequest(req))

}
Output:
POST /users/1?k1=1&k2=1&k2=2&k2=3 HTTP/1.1
Content-Length: 21
Content-Type: applicaiton/json
User-Agent: goland

{"k1":100,"k2":"200"}

Types

This section is empty.

Jump to

Keyboard shortcuts

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