http

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertFileContent

func AssertFileContent(t TestingT, storage *storageTesting.FakeStorage, path string, expectedContent []byte)

AssertFileContent checks if uploaded file has expected content

func AssertFileUploaded

func AssertFileUploaded(t TestingT, storage *storageTesting.FakeStorage, expectedPath string)

AssertFileUploaded checks if a file was successfully uploaded

func GetUploadedFile

func GetUploadedFile(r *http.Request, fieldName string) (multipart.File, *multipart.FileHeader, error)

GetUploadedFile retrieves an uploaded file from the request

func GetUploadedFiles

func GetUploadedFiles(r *http.Request, fieldName string) ([]*multipart.FileHeader, error)

GetUploadedFiles retrieves multiple uploaded files from the request

func ParseMultipartForm

func ParseMultipartForm(r *http.Request, maxMemory int64) error

ParseMultipartForm is a helper to parse multipart form in tests

func SaveUploadedFile

func SaveUploadedFile(file multipart.File, header *multipart.FileHeader, basePath string) (string, error)

SaveUploadedFile saves an uploaded file to storage (helper for handlers)

func TestMultipleUploads

func TestMultipleUploads(files map[string]*storageTesting.FakeFile) *http.Request

TestMultipleUploads creates a request with multiple file uploads

func TestUpload

func TestUpload(fieldName string, file *storageTesting.FakeFile) *http.Request

TestUpload creates a simple file upload request for testing

func TestUploadHandler

func TestUploadHandler(storage storageTesting.FakeStorage) http.HandlerFunc

TestUploadHandler creates a test handler that processes file uploads

Types

type TestUploadBuilder

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

TestUploadBuilder helps build test upload requests

func NewUploadBuilder

func NewUploadBuilder() *TestUploadBuilder

NewUploadBuilder creates a new upload builder

func (*TestUploadBuilder) AddField

func (b *TestUploadBuilder) AddField(name, value string) *TestUploadBuilder

AddField adds a form field to the upload

func (*TestUploadBuilder) AddFile

func (b *TestUploadBuilder) AddFile(fieldName string, file *storageTesting.FakeFile) *TestUploadBuilder

AddFile adds a file to the upload

func (*TestUploadBuilder) AddHeader

func (b *TestUploadBuilder) AddHeader(name, value string) *TestUploadBuilder

AddHeader adds a header to the request

func (*TestUploadBuilder) AddRawFile

func (b *TestUploadBuilder) AddRawFile(fieldName, fileName string, content []byte, mimeType string) *TestUploadBuilder

AddRawFile adds a raw file to the upload

func (*TestUploadBuilder) Build

func (b *TestUploadBuilder) Build(method, url string) (*http.Request, error)

Build creates the multipart request

func (*TestUploadBuilder) BuildTest

func (b *TestUploadBuilder) BuildTest(method, url string) *http.Request

BuildTest creates a test request for httptest

type TestingT

type TestingT interface {
	Helper()
	Errorf(format string, args ...interface{})
}

TestingT is a subset of testing.T for helper functions

type UploadResponse

type UploadResponse struct {
	Success bool                   `json:"success"`
	Message string                 `json:"message,omitempty"`
	Files   []UploadedFileResponse `json:"files,omitempty"`
	Errors  map[string]string      `json:"errors,omitempty"`
}

UploadResponse represents a typical upload response

type UploadedFile

type UploadedFile struct {
	FieldName string
	FileName  string
	Content   []byte
	MimeType  string
}

UploadedFile represents a file to be uploaded in tests

type UploadedFileResponse

type UploadedFileResponse struct {
	Name         string `json:"name"`
	Path         string `json:"path"`
	URL          string `json:"url"`
	Size         int64  `json:"size"`
	MimeType     string `json:"mime_type"`
	TemporaryURL string `json:"temporary_url,omitempty"`
}

UploadedFileResponse represents a single uploaded file in the response

Jump to

Keyboard shortcuts

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