Skip to content

testing #

fn build_user_fixture #

fn build_user_fixture() UserFixture

build_user_fixture creates a user fixture with defaults

fn load_sql_fixture #

fn load_sql_fixture(mut db database.DB, filename string) !

load_sql_fixture executes SQL from a fixture file Useful for loading complex test data scenarios

fn random_string #

fn random_string(length int) string

random_string generates a random string of specified length

fn seed_test_data #

fn seed_test_data(mut db database.DB) !

seed_test_data populates database with common test data

fn truncate_tables #

fn truncate_tables(mut db database.DB, tables []string) !

truncate_tables clears specified tables (useful for test setup)

fn unique_email #

fn unique_email() string

unique_email returns a unique email address for fixtures

fn unique_int #

fn unique_int() int

unique_int returns a unique integer for fixtures based on timestamp

fn unique_string #

fn unique_string(prefix string) string

unique_string returns a unique string for fixtures

struct TestResponse #

struct TestResponse {
pub:
	status  int
	headers map[string]string
	body    string
	cookies map[string]string
}

TestResponse wraps HTTP response with assertion helpers

fn (TestResponse) assert_accepted #

fn (resp &TestResponse) assert_accepted()

assert_accepted asserts response status is 202 Accepted

fn (TestResponse) assert_bad_request #

fn (resp &TestResponse) assert_bad_request()

assert_bad_request asserts response status is 400

fn (TestResponse) assert_body_contains #

fn (resp &TestResponse) assert_body_contains(substring string)

assert_body_contains asserts body contains substring

fn (TestResponse) assert_body_empty #

fn (resp &TestResponse) assert_body_empty()

assert_body_empty asserts body is empty

fn (TestResponse) assert_body_equals #

fn (resp &TestResponse) assert_body_equals(expected string)

assert_body_equals asserts body exactly matches string

fn (TestResponse) assert_body_not_contains #

fn (resp &TestResponse) assert_body_not_contains(substring string)

assert_body_not_contains asserts body does not contain substring

fn (TestResponse) assert_body_not_empty #

fn (resp &TestResponse) assert_body_not_empty()

assert_body_not_empty asserts body is not empty

fn (TestResponse) assert_client_error #

fn (resp &TestResponse) assert_client_error()

assert_client_error asserts response is client error (4xx)

fn (TestResponse) assert_conflict #

fn (resp &TestResponse) assert_conflict()

assert_conflict asserts response status is 409

fn (TestResponse) assert_content_type #

fn (resp &TestResponse) assert_content_type(expected string)

assert_content_type asserts Content-Type header

fn (TestResponse) assert_created #

fn (resp &TestResponse) assert_created()

assert_created asserts response status is 201 Created

fn (TestResponse) assert_forbidden #

fn (resp &TestResponse) assert_forbidden()

assert_forbidden asserts response status is 403

fn (TestResponse) assert_found #

fn (resp &TestResponse) assert_found()

assert_found asserts response status is 302

fn (TestResponse) assert_header #

fn (resp &TestResponse) assert_header(name string, expected string)

assert_header asserts specific header exists with expected value

fn (TestResponse) assert_header_exists #

fn (resp &TestResponse) assert_header_exists(name string)

assert_header_exists asserts header exists (any value)

fn (TestResponse) assert_header_missing #

fn (resp &TestResponse) assert_header_missing(name string)

assert_header_missing asserts header does not exist

fn (TestResponse) assert_html #

fn (resp &TestResponse) assert_html()

assert_html asserts response is HTML

fn (TestResponse) assert_internal_error #

fn (resp &TestResponse) assert_internal_error()

assert_internal_error asserts response status is 500

fn (TestResponse) assert_json #

fn (resp &TestResponse) assert_json()

assert_json asserts response is JSON

fn (TestResponse) assert_method_not_allowed #

fn (resp &TestResponse) assert_method_not_allowed()

assert_method_not_allowed asserts response status is 405

fn (TestResponse) assert_moved_permanently #

fn (resp &TestResponse) assert_moved_permanently()

assert_moved_permanently asserts response status is 301

fn (TestResponse) assert_no_content #

fn (resp &TestResponse) assert_no_content()

assert_no_content asserts response status is 204 No Content

fn (TestResponse) assert_not_found #

fn (resp &TestResponse) assert_not_found()

assert_not_found asserts response status is 404

fn (TestResponse) assert_ok #

fn (resp &TestResponse) assert_ok()

assert_ok asserts response status is 200 OK

fn (TestResponse) assert_redirect #

fn (resp &TestResponse) assert_redirect()

assert_redirect asserts response status is 3xx redirect

fn (TestResponse) assert_redirect_to #

fn (resp &TestResponse) assert_redirect_to(location string)

assert_redirect_to asserts response redirects to specific location

fn (TestResponse) assert_server_error #

fn (resp &TestResponse) assert_server_error()

assert_server_error asserts response is server error (5xx)

fn (TestResponse) assert_status #

fn (resp &TestResponse) assert_status(expected int)

assert_status asserts response has specific status code

fn (TestResponse) assert_success #

fn (resp &TestResponse) assert_success()

assert_success asserts response is successful (2xx)

fn (TestResponse) assert_temporary_redirect #

fn (resp &TestResponse) assert_temporary_redirect()

assert_temporary_redirect asserts response status is 307

fn (TestResponse) assert_unauthorized #

fn (resp &TestResponse) assert_unauthorized()

assert_unauthorized asserts response status is 401

fn (TestResponse) assert_unprocessable_entity #

fn (resp &TestResponse) assert_unprocessable_entity()

assert_unprocessable_entity asserts response status is 422

struct UserFixture #

struct UserFixture {
pub mut:
	username string
	email    string
	password string = 'test123456'
}

Fixture builder pattern This allows creating test data with sensible defaults and overrides

fn (UserFixture) with_username #

fn (mut f UserFixture) with_username(username string) UserFixture

with_username sets username on fixture (builder pattern)

fn (UserFixture) with_email #

fn (mut f UserFixture) with_email(email string) UserFixture

with_email sets email on fixture (builder pattern)

fn (UserFixture) with_password #

fn (mut f UserFixture) with_password(password string) UserFixture

with_password sets password on fixture (builder pattern)