Documentation
¶
Overview ¶
Package test provides utilities for setting up and running tests
Index ¶
- Constants
- func NewInMemoryDB() (*gorm.DB, error)
- func NewTestDOClient() *mocks.MockDOClient
- func NewTestProvider() compute.Provider
- func Run(t *testing.T)
- func RunMigrations(db *gorm.DB) error
- func SetupMockDOClient(suite *Suite)
- func SetupServer(suite *Suite)
- func SetupTestDB(suite *Suite, database *gorm.DB)
- type Suite
- func (s *Suite) Cleanup()
- func (s *Suite) Context() context.Context
- func (s *Suite) Require() *require.Assertions
- func (s *Suite) Retry(fn func() error, retries int, interval time.Duration) (err error)
- func (s *Suite) SetS(_ suite.TestingSuite)
- func (s *Suite) SetT(t *testing.T)
- func (s *Suite) SetupSuite()
- func (s *Suite) T() *testing.T
- func (s *Suite) TearDownSuite()
Constants ¶
const DefaultTestTimeout = 30 * time.Second
DefaultTestTimeout is the default timeout for test suites.
Variables ¶
This section is empty.
Functions ¶
func NewInMemoryDB ¶
NewInMemoryDB creates a new in-memory SQLite database for testing.
func NewTestDOClient ¶
func NewTestDOClient() *mocks.MockDOClient
NewTestDOClient creates a new test DigitalOcean client instance
func NewTestProvider ¶
NewTestProvider creates a new test provider instance
func RunMigrations ¶
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 ¶
SetupTestDB configures the test suite to use the provided database connection. If nil is provided, a new in-memory 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 ¶
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 ¶
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 ¶
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) TearDownSuite ¶
func (s *Suite) TearDownSuite()
TearDownSuite tears down the test suite