MCPcopy Create free account
hub / github.com/astercloud/aster / TestService

Function TestService

pkg/session/sqlite/store_test.go:15–171  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestService(t *testing.T) {
16 // Create temporary database
17 tmpDir := t.TempDir()
18 dbPath := filepath.Join(tmpDir, "test.db")
19
20 svc, err := New(dbPath)
21 if err != nil {
22 t.Fatalf("New failed: %v", err)
23 }
24 defer func() { _ = svc.Close() }()
25
26 ctx := context.Background()
27
28 // Test Create
29 t.Run("Create", func(t *testing.T) {
30 sess, err := svc.Create(ctx, &session.CreateRequest{
31 AppName: "test-app",
32 UserID: "user-1",
33 AgentID: "agent-1",
34 Metadata: map[string]any{
35 "test": "value",
36 },
37 })
38 if err != nil {
39 t.Fatalf("Create failed: %v", err)
40 }
41
42 if sess.ID() == "" {
43 t.Error("Session ID should not be empty")
44 }
45 if sess.AppName() != "test-app" {
46 t.Errorf("Expected app name 'test-app', got %q", sess.AppName())
47 }
48 if sess.UserID() != "user-1" {
49 t.Errorf("Expected user ID 'user-1', got %q", sess.UserID())
50 }
51 })
52
53 // Test Get
54 t.Run("Get", func(t *testing.T) {
55 // Create a session first
56 created, _ := svc.Create(ctx, &session.CreateRequest{
57 AppName: "test-app",
58 UserID: "user-1",
59 AgentID: "agent-1",
60 })
61
62 // Get the session
63 sess, err := svc.Get(ctx, &session.GetRequest{
64 AppName: "test-app",
65 UserID: "user-1",
66 SessionID: created.ID(),
67 })
68 if err != nil {
69 t.Fatalf("Get failed: %v", err)
70 }
71
72 if sess.ID() != created.ID() {

Callers

nothing calls this directly

Calls 14

NewFunction · 0.70
CloseMethod · 0.65
CreateMethod · 0.65
IDMethod · 0.65
ErrorMethod · 0.65
AppNameMethod · 0.65
UserIDMethod · 0.65
GetMethod · 0.65
UpdateMethod · 0.65
MetadataMethod · 0.65
ListMethod · 0.65
DeleteMethod · 0.65

Tested by

no test coverage detected