test

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: May 19, 2025 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package test provides utilities for setting up and running tests

Index

Constants

View Source
const DefaultTestTimeout = 30 * time.Second

DefaultTestTimeout is the default timeout for test suites.

Variables

This section is empty.

Functions

func CleanupTestDB added in v0.0.9

func CleanupTestDB(db *gorm.DB, tmpDir string)

CleanupTestDB closes the database connection and removes the temporary directory.

func NewFileBasedTestDB added in v0.0.9

func NewFileBasedTestDB() (*gorm.DB, string, error)

NewFileBasedTestDB creates a new file-based SQLite database for testing. It returns the database connection and the path to the temporary directory.

func NewTestDOClient

func NewTestDOClient() *mocks.MockDOClient

NewTestDOClient creates a new test DigitalOcean client instance

func NewTestProvider

func NewTestProvider() compute.Provider

NewTestProvider creates a new test provider instance

func Run

func Run(t *testing.T)

Run runs the test suite

func RunMigrations

func RunMigrations(db *gorm.DB) error

RunMigrations runs all database migrations for the test database.

func SetupMockDOClient

func SetupMockDOClient(suite *Suite)

SetupMockDOClient sets up a mock DigitalOcean client

func SetupServer

func SetupServer(suite *Suite)

SetupServer configures the test suite with a real API server

func SetupTestDB

func SetupTestDB(suite *Suite, database *gorm.DB)

SetupTestDB configures the test suite to use the provided database connection. If nil is provided, a new file-based database will be created.

Types

type Suite

type Suite struct {

	// Server components
	App    *fiber.App
	Server *httptest.Server

	// Client components
	APIClient client.Client

	// Database components
	DB           *gorm.DB
	InstanceRepo *repos.InstanceRepository
	UserRepo     *repos.UserRepository
	ProjectRepo  *repos.ProjectRepository
	TaskRepo     *repos.TaskRepository

	// Mock providers
	MockDOClient *mocks.MockDOClient
	// contains filtered or unexported fields
}

Suite encapsulates all components needed for integration testing. It provides a complete test setup with:

  • In-memory database
  • Real API server
  • Real API client
  • Mocked external providers

func NewSuite

func NewSuite(t *testing.T) *Suite

NewSuite creates a new test suite with the given options. The suite must be cleaned up after use by calling Cleanup.

func (*Suite) Cleanup

func (s *Suite) Cleanup()

Cleanup tears down the test suite, releasing all resources. This should be deferred immediately after creating the suite.

func (*Suite) Context

func (s *Suite) Context() context.Context

Context returns the suite's context, which is automatically canceled when the suite is cleaned up.

func (*Suite) Require

func (s *Suite) Require() *require.Assertions

Require returns a require.Assertions instance for this suite. This is a convenience method to avoid passing t around.

func (*Suite) Retry

func (s *Suite) Retry(fn func() error, retries int, interval time.Duration) (err error)

Retry retries a function until it succeeds or the number of retries is reached.

func (*Suite) SetS

func (s *Suite) SetS(_ suite.TestingSuite)

SetS sets the suite instance for this suite

func (*Suite) SetT

func (s *Suite) SetT(t *testing.T)

SetT sets the testing.T instance for this suite

func (*Suite) SetupSuite

func (s *Suite) SetupSuite()

SetupSuite sets up the test suite

func (*Suite) T

func (s *Suite) T() *testing.T

T returns the testing.T instance for this suite

func (*Suite) TearDownSuite

func (s *Suite) TearDownSuite()

TearDownSuite tears down the test suite

Directories

Path Synopsis
Package mocks provides mock implementations for external services and APIs used in testing
Package mocks provides mock implementations for external services and APIs used in testing

Jump to

Keyboard shortcuts

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