| 13 | ) |
| 14 | |
| 15 | func 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() { |