test

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: May 26, 2023 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package test provides some utilities for integration testing at endpoint levels.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDB

func NewDB(t *testing.T) *db.DB

NewDB creates and populates a test database.

Types

type ReqOpt

type ReqOpt func(*http.Request)

ReqOpt is an option for sending requests.

type TestServer

type TestServer struct {
	*server.Server
	DB *db.DB
}

TestServer wraps Server and adds some fancy stuff.

func NewServer

func NewServer(t *testing.T) *TestServer

NewServer creates a new kjudge server running on a test database.

func (*TestServer) Get

func (ts *TestServer) Get(t *testing.T, path string, queries url.Values) *http.Request

Get fires a new GET request with URL queries.

func (*TestServer) PostForm

func (ts *TestServer) PostForm(t *testing.T, path string, body url.Values) *http.Request

PostForm fires a new POST request with a form body.

func (*TestServer) Serve

func (ts *TestServer) Serve(req *http.Request, opts ...ReqOpt) *http.Response

Serve serves a HTTP request and returns its response.

func (*TestServer) WithAdmin

func (ts *TestServer) WithAdmin(t *testing.T) ReqOpt

WithAdmin logs in with the admin panel cookie for the next request.

func (*TestServer) WithMisaka

func (ts *TestServer) WithMisaka(t *testing.T) ReqOpt

WithMisaka logs in as Misaka for the next request.

Jump to

Keyboard shortcuts

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