testing

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TestApp

type TestApp struct {
	App    *fiber.App
	DB     *gorm.DB
	Server *httptest.Server
}

TestApp represents a test application instance

func NewTestApp

func NewTestApp(t *testing.T, config *TestConfig) *TestApp

NewTestApp creates a new test application

func (*TestApp) Close

func (ta *TestApp) Close()

Close closes the test app and cleans up resources

func (*TestApp) Delete

func (ta *TestApp) Delete(t *testing.T, path string, headers map[string]string) *TestResponse

Delete performs a DELETE request

func (*TestApp) Get

func (ta *TestApp) Get(t *testing.T, path string) *TestResponse

Get performs a GET request

func (*TestApp) Post

func (ta *TestApp) Post(t *testing.T, path string, body interface{}, headers map[string]string) *TestResponse

Post performs a POST request

func (*TestApp) Put

func (ta *TestApp) Put(t *testing.T, path string, body interface{}, headers map[string]string) *TestResponse

Put performs a PUT request

func (*TestApp) Request

func (ta *TestApp) Request(t *testing.T, method, path string, body interface{}, headers map[string]string) *TestResponse

Request performs an HTTP request

type TestAssertion

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

TestAssertion provides custom assertion utilities

func NewTestAssertion

func NewTestAssertion(t *testing.T) *TestAssertion

NewTestAssertion creates a new test assertion

func (*TestAssertion) AssertEmpty

func (ta *TestAssertion) AssertEmpty(value interface{}, msg ...string)

AssertEmpty asserts that a value is empty

func (*TestAssertion) AssertError

func (ta *TestAssertion) AssertError(err error, msg ...string)

AssertError asserts that there is an error

func (*TestAssertion) AssertNoError

func (ta *TestAssertion) AssertNoError(err error, msg ...string)

AssertNoError asserts that there is no error

func (*TestAssertion) AssertNotEmpty

func (ta *TestAssertion) AssertNotEmpty(value interface{}, msg ...string)

AssertNotEmpty asserts that a value is not empty

type TestConfig

type TestConfig struct {
	DatabaseDriver string
	DatabaseDSN    string
	Port           int
	Debug          bool
}

TestConfig holds test configuration

func DefaultTestConfig

func DefaultTestConfig() *TestConfig

DefaultTestConfig returns default test configuration

type TestDataProvider

type TestDataProvider struct {
	Data map[string]interface{}
}

TestDataProvider provides test data utilities

func NewTestDataProvider

func NewTestDataProvider() *TestDataProvider

NewTestDataProvider creates a new test data provider

func (*TestDataProvider) Clear

func (tdp *TestDataProvider) Clear()

Clear clears all test data

func (*TestDataProvider) Get

func (tdp *TestDataProvider) Get(key string) interface{}

Get gets a test data value

func (*TestDataProvider) GetBool

func (tdp *TestDataProvider) GetBool(key string) bool

GetBool gets a test data value as bool

func (*TestDataProvider) GetInt

func (tdp *TestDataProvider) GetInt(key string) int

GetInt gets a test data value as int

func (*TestDataProvider) GetString

func (tdp *TestDataProvider) GetString(key string) string

GetString gets a test data value as string

func (*TestDataProvider) Set

func (tdp *TestDataProvider) Set(key string, value interface{})

Set sets a test data value

type TestEnvironment

type TestEnvironment struct {
	TempDir string
	Files   []*TestFile
}

TestEnvironment represents a test environment

func NewTestEnvironment

func NewTestEnvironment(t *testing.T) *TestEnvironment

NewTestEnvironment creates a new test environment

func (*TestEnvironment) AddFile

func (te *TestEnvironment) AddFile(t *testing.T, name, content string) *TestFile

AddFile adds a file to the test environment

func (*TestEnvironment) Cleanup

func (te *TestEnvironment) Cleanup(t *testing.T)

Cleanup cleans up the test environment

func (*TestEnvironment) GetPath

func (te *TestEnvironment) GetPath(name string) string

GetPath returns the full path for a file in the test environment

type TestFactory

type TestFactory struct {
	DB *gorm.DB
}

TestFactory provides factory methods for creating test data

func NewTestFactory

func NewTestFactory(db *gorm.DB) *TestFactory

NewTestFactory creates a new test factory

func (*TestFactory) CleanupDatabase

func (tf *TestFactory) CleanupDatabase()

CleanupDatabase cleans up test database

func (*TestFactory) CreatePermission

func (tf *TestFactory) CreatePermission(overrides ...map[string]interface{}) *TestPermission

CreatePermission creates a test permission

func (*TestFactory) CreatePost

func (tf *TestFactory) CreatePost(userID uint, overrides ...map[string]interface{}) *TestPost

CreatePost creates a test post

func (*TestFactory) CreateRole

func (tf *TestFactory) CreateRole(overrides ...map[string]interface{}) *TestRole

CreateRole creates a test role

func (*TestFactory) CreateUser

func (tf *TestFactory) CreateUser(overrides ...map[string]interface{}) *TestUser

CreateUser creates a test user

type TestFile

type TestFile struct {
	Name    string
	Content []byte
	Path    string
}

TestFile represents a test file

func CreateTestFile

func CreateTestFile(t *testing.T, name, content string) *TestFile

CreateTestFile creates a test file

func (*TestFile) Remove

func (tf *TestFile) Remove(t *testing.T)

Remove removes the test file from disk

func (*TestFile) Write

func (tf *TestFile) Write(t *testing.T)

Write writes the test file to disk

type TestHelper

type TestHelper struct {
	App     *fiber.App
	DB      *gorm.DB
	Factory *TestFactory
}

TestHelper provides common test utilities

func NewTestHelper

func NewTestHelper(t *testing.T) *TestHelper

NewTestHelper creates a new test helper

func (*TestHelper) Cleanup

func (th *TestHelper) Cleanup()

Cleanup cleans up test resources

func (*TestHelper) Request

func (th *TestHelper) Request(t *testing.T, method, path string, body interface{}, headers map[string]string) *TestResponse

Request performs an HTTP request using the Fiber app

func (*TestHelper) SetupTestRoutes

func (th *TestHelper) SetupTestRoutes()

SetupTestRoutes sets up common test routes

type TestLogger

type TestLogger struct {
	Messages []string
}

TestLogger provides test logging utilities

func NewTestLogger

func NewTestLogger() *TestLogger

NewTestLogger creates a new test logger

func (*TestLogger) AssertLogged

func (tl *TestLogger) AssertLogged(t *testing.T, expected string)

AssertLogged asserts that a message was logged

func (*TestLogger) Clear

func (tl *TestLogger) Clear()

Clear clears all logged messages

func (*TestLogger) GetMessages

func (tl *TestLogger) GetMessages() []string

GetMessages returns all logged messages

func (*TestLogger) Log

func (tl *TestLogger) Log(msg string)

Log logs a message

type TestPermission

type TestPermission struct {
	ID          uint      `json:"id" gorm:"primaryKey"`
	Name        string    `json:"name" gorm:"uniqueIndex"`
	Description string    `json:"description"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

TestPermission represents a test permission model

type TestPost

type TestPost struct {
	ID        uint      `json:"id" gorm:"primaryKey"`
	Title     string    `json:"title"`
	Content   string    `json:"content"`
	UserID    uint      `json:"user_id"`
	User      TestUser  `json:"user" gorm:"foreignKey:UserID"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

TestPost represents a test post model

type TestResponse

type TestResponse struct {
	StatusCode int
	Headers    http.Header
	Body       []byte
}

TestResponse represents an HTTP test response

func (*TestResponse) AssertContains

func (tr *TestResponse) AssertContains(t *testing.T, expected string)

AssertContains asserts the response body contains a substring

func (*TestResponse) AssertHeader

func (tr *TestResponse) AssertHeader(t *testing.T, key, expected string)

AssertHeader asserts a response header value

func (*TestResponse) AssertJSON

func (tr *TestResponse) AssertJSON(t *testing.T, expected interface{})

AssertJSON asserts the response body matches expected JSON

func (*TestResponse) AssertStatus

func (tr *TestResponse) AssertStatus(t *testing.T, expected int)

AssertStatus asserts the response status code

func (*TestResponse) GetJSON

func (tr *TestResponse) GetJSON(t *testing.T, target interface{})

GetJSON unmarshals the response body into the target

type TestRole

type TestRole struct {
	ID          uint           `json:"id" gorm:"primaryKey"`
	Name        string         `json:"name" gorm:"uniqueIndex"`
	Description string         `json:"description"`
	CreatedAt   time.Time      `json:"created_at"`
	UpdatedAt   time.Time      `json:"updated_at"`
	DeletedAt   gorm.DeletedAt `json:"deleted_at" gorm:"index"`
}

TestRole represents a test role model

type TestTimeout

type TestTimeout struct {
	Duration time.Duration
}

TestTimeout provides timeout utilities for tests

func NewTestTimeout

func NewTestTimeout(duration time.Duration) *TestTimeout

NewTestTimeout creates a new test timeout

func (*TestTimeout) WithTimeout

func (tt *TestTimeout) WithTimeout(t *testing.T, fn func())

WithTimeout runs a function with a timeout

type TestUser

type TestUser struct {
	ID        uint      `json:"id" gorm:"primaryKey"`
	Email     string    `json:"email" gorm:"uniqueIndex"`
	Password  string    `json:"-"`
	Name      string    `json:"name"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

TestUser represents a test user model

Jump to

Keyboard shortcuts

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