mirror of
https://github.com/SamyRai/turash.git
synced 2025-12-26 23:01:33 +00:00
Some checks failed
CI/CD Pipeline / backend-lint (push) Failing after 1m1s
CI/CD Pipeline / backend-build (push) Has been skipped
CI/CD Pipeline / frontend-lint (push) Successful in 1m37s
CI/CD Pipeline / frontend-build (push) Failing after 35s
CI/CD Pipeline / e2e-test (push) Has been skipped
- Replace pgtestdb with Testcontainers for improved test isolation and reliability - Update test setup functions to spin up dedicated PostgreSQL containers for each test - Ensure automatic cleanup of containers after tests to prevent resource leaks - Modify documentation to reflect changes in testing methodology and benefits of using Testcontainers
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package testutils
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"bugulma/backend/internal/domain"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestSetupTestDBWithTestcontainers(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
// Test the testcontainers-based database setup
|
|
// This verifies that PostgreSQL containers start correctly and migrations run
|
|
db := SetupTestDBWithTestcontainers(t)
|
|
assert.NotNil(t, db)
|
|
|
|
// Test creating an organization first (required for foreign key constraints)
|
|
org := &domain.Organization{
|
|
ID: "org-1",
|
|
Name: "Test Organization",
|
|
}
|
|
err := db.Create(org).Error
|
|
assert.NoError(t, err)
|
|
|
|
// Test creating a site (this should work with PostgreSQL)
|
|
site := &domain.Site{
|
|
ID: "site-1",
|
|
Name: "Test Site",
|
|
Latitude: 52.52,
|
|
Longitude: 13.405,
|
|
OwnerOrganizationID: "org-1",
|
|
}
|
|
err = db.Create(site).Error
|
|
assert.NoError(t, err)
|
|
|
|
// Test that we can query it back
|
|
var retrieved domain.Site
|
|
err = db.First(&retrieved, "id = ?", "site-1").Error
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, "Test Site", retrieved.Name)
|
|
assert.Equal(t, 52.52, retrieved.Latitude)
|
|
}
|