testutil

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: MIT Imports: 6 Imported by: 0

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 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