backendtest

package
v0.17.5 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package backendtest provides shared helpers for tests that stand up a mock Confab backend with net/http/httptest.

It exists because pkg/http compresses request bodies over 1KB with zstd (see pkg/http/client.go). A mock handler that decodes r.Body as raw JSON therefore works only while payloads stay small, and silently mis-decodes larger ones into zero-valued structs — a false green, or (when the handler echoes a line count back) a spurious re-send. Read every mock backend's body through ReadRequestBody so body size never changes test behavior.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decompress

func Decompress(contentEncoding string, body []byte) []byte

Decompress returns body decoded per contentEncoding. Use it when the test needs the raw bytes too (e.g. to assert on compressed transfer size); otherwise prefer ReadRequestBody. Returns body unchanged for any encoding other than zstd, and on a decode failure — a mock backend should not panic on a malformed body.

func ReadRequestBody

func ReadRequestBody(r *http.Request) ([]byte, error)

ReadRequestBody reads r.Body, transparently decompressing it when the client sent Content-Encoding: zstd.

Types

This section is empty.

Jump to

Keyboard shortcuts

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