MCPcopy
hub / github.com/usememos/memos / NewTestService

Function NewTestService

server/router/api/v1/test/test_helper.go:24–62  ·  view source on GitHub ↗

NewTestService creates a new test service with SQLite database.

(t *testing.T)

Source from the content-addressed store, hash-verified

22
23// NewTestService creates a new test service with SQLite database.
24func 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.
65func (ts *TestService) Cleanup() {

Calls 4

NewServiceFunction · 0.92
WithTagExtensionFunction · 0.92
WithMentionExtensionFunction · 0.92
GetDataDirMethod · 0.80