test

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BuildName = "build.data"
	BuildSize = 200 * 1024 * 1024
	Dir       = "./"
	BuildFile = Dir + BuildName

	ExternalDownloadUrl  = "https://raw.githubusercontent.com/GopeedLab/gopeed/v1.5.6/_docs/img/banner.png"
	ExternalDownloadName = "banner.png"
	ExternalDownloadSize = 26416

	DownloadName       = "download.data"
	DownloadRename     = "download (1).data"
	DownloadFile       = Dir + DownloadName
	DownloadRenameFile = Dir + DownloadRename

	// TestChineseFileName is a common test filename with Chinese characters
	// Used to test Content-Disposition parsing with various encodings
	TestChineseFileName = "测试.zip"
)

Variables

This section is empty.

Functions

func AssertResourceEqual added in v1.5.4

func AssertResourceEqual(want, got *base.Resource) bool

func DirMd5

func DirMd5(dirPath string) string

func FileMd5

func FileMd5(filePath string) string

func JsonEqual

func JsonEqual(v1 any, v2 any) bool

func StartSocks5Server added in v1.5.1

func StartSocks5Server(usr, pwd string) net.Listener

func StartTestCookieExpiringServer added in v1.9.1

func StartTestCookieExpiringServer() net.Listener

StartTestCookieExpiringServer creates a server that simulates cookie expiration during download. - First request (Resolve): accepts "session=old_token" and succeeds - Subsequent requests: "session=old_token" is expired (returns 401), only "session=new_token" works This is used to test the Patch functionality where a cookie expires mid-download, requiring the user to patch with a new cookie to resume.

func StartTestCustomServer added in v1.3.3

func StartTestCustomServer() net.Listener

func StartTestErrorServer

func StartTestErrorServer() net.Listener

func StartTestExpiringRedirectServer added in v1.9.1

func StartTestExpiringRedirectServer(requestsBeforeExpire int32, delayPerByte time.Duration) net.Listener

StartTestExpiringRedirectServer creates a server that simulates expiring redirect URLs. The original URL redirects to a temporary URL that expires after a specified number of requests. When the temporary URL expires (returns 403), the client should retry with the original URL to get a new redirect URL. Parameters:

  • requestsBeforeExpire: number of requests the temporary URL accepts before expiring
  • delayPerByte: optional delay per byte for slow transfer (use 0 for no delay)

func StartTestFailThenRecoverServer added in v1.9.1

func StartTestFailThenRecoverServer(failedRequestsBeforeRecover int32) net.Listener

StartTestFailThenRecoverServer creates a server that fails all connections initially, then recovers after a specified number of failed requests. This tests the retry functionality when calling Start() again after a download fails. Parameters:

  • failedRequestsBeforeRecover: number of requests that will fail before server recovers

Note: Uses 416 (Range Not Satisfiable) instead of 500 because 5xx errors are exempt from failure counting and will retry indefinitely. 416 is counted as a failure.

func StartTestFileServer

func StartTestFileServer() net.Listener

func StartTestHostHeaderServer added in v1.9.0

func StartTestHostHeaderServer() net.Listener

StartTestHostHeaderServer starts a server that validates the Host header Returns 400 Bad Request if the Host header value equals "test"

func StartTestLimitServer added in v1.4.2

func StartTestLimitServer(maxConnections int32, delay int64) net.Listener

StartTestLimitServer connections limit server

func StartTestOneTimeServer added in v1.9.0

func StartTestOneTimeServer() net.Listener

StartTestOneTimeServer creates a server where the URL can only be downloaded once The first non-probe request succeeds, all subsequent requests return 404 This simulates one-time download URLs (e.g., signed URLs that expire after first use)

func StartTestPatchURLServer added in v1.9.1

func StartTestPatchURLServer() net.Listener

StartTestPatchURLServer creates a server with two endpoints: - /bad-url: always returns 404 (simulates a broken download link) - /good-url: returns the file successfully (simulates a working download link) This is used to test the Patch functionality where a failed download URL can be replaced with a working one.

func StartTestPostServer

func StartTestPostServer() net.Listener

func StartTestRangeBugServer added in v1.6.11

func StartTestRangeBugServer() net.Listener

StartTestRangeBugServer simulate bug server: Don't follow Range request rules, always return more data than range, e.g. Range: bytes=0-100, return 150 bytes

func StartTestRetryServer

func StartTestRetryServer() net.Listener

func StartTestSlowFileServer

func StartTestSlowFileServer(delay time.Duration) net.Listener

func StartTestSlowStartServer added in v1.9.0

func StartTestSlowStartServer(delayPerByte time.Duration) net.Listener

StartTestSlowStartServer creates a server with configurable delay per request This allows testing slow-start connection expansion to reach max connections

func StartTestTemporary500Server added in v1.9.0

func StartTestTemporary500Server(errorDuration time.Duration) net.Listener

StartTestTemporary500Server creates a server that returns 500 for a duration, then recovers Uses slow transfer to ensure the file isn't fully downloaded during resolve phase

func StartTestTimeoutOnceServer added in v1.9.0

func StartTestTimeoutOnceServer(delay int64) net.Listener

StartTestTimeoutOnceServer creates a server that times out on first request, then works normally

func ToJson

func ToJson(v interface{}) string

Types

type SlowFileServer

type SlowFileServer struct {
	// contains filtered or unexported fields
}

func (*SlowFileServer) ServeHTTP

func (s *SlowFileServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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