NewTestService creates a new test service with SQLite database.
(t *testing.T)
| 22 | |
| 23 | // NewTestService creates a new test service with SQLite database. |
| 24 | func NewTestService(t *testing.T) *TestService { |
| 25 | ctx := context.Background() |
| 26 | |
| 27 | // Create a test store with SQLite |
| 28 | testStore := teststore.NewTestingStore(ctx, t) |
| 29 | |
| 30 | // Align the profile data directory with the test store so attachment files and |
| 31 | // derived caches resolve against the same location as DeleteAttachmentStorage. |
| 32 | testProfile := &profile.Profile{ |
| 33 | Demo: true, |
| 34 | Version: "test-1.0.0", |
| 35 | Commit: "test-commit", |
| 36 | InstanceURL: "http://localhost:8080", |
| 37 | Driver: "sqlite", |
| 38 | DSN: ":memory:", |
| 39 | Data: testStore.GetDataDir(), |
| 40 | } |
| 41 | |
| 42 | // Create APIV1Service with nil grpcServer since we're testing direct calls |
| 43 | secret := "test-secret" |
| 44 | markdownService := markdown.NewService( |
| 45 | markdown.WithTagExtension(), |
| 46 | markdown.WithMentionExtension(), |
| 47 | ) |
| 48 | service := &apiv1.APIV1Service{ |
| 49 | Secret: secret, |
| 50 | Profile: testProfile, |
| 51 | Store: testStore, |
| 52 | MarkdownService: markdownService, |
| 53 | SSEHub: apiv1.NewSSEHub(), |
| 54 | } |
| 55 | |
| 56 | return &TestService{ |
| 57 | Service: service, |
| 58 | Store: testStore, |
| 59 | Profile: testProfile, |
| 60 | Secret: secret, |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | // Cleanup closes resources after test. |
| 65 | func (ts *TestService) Cleanup() { |