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

Function TestState

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

Source from the content-addressed store, hash-verified

255}
256
257func TestState(t *testing.T) {
258 tmpDir := t.TempDir()
259 dbPath := filepath.Join(tmpDir, "test.db")
260
261 svc, err := New(dbPath)
262 if err != nil {
263 t.Fatalf("New failed: %v", err)
264 }
265 defer func() { _ = svc.Close() }()
266
267 ctx := context.Background()
268
269 // Create session
270 sess, _ := svc.Create(ctx, &session.CreateRequest{
271 AppName: "test-app",
272 UserID: "user-1",
273 AgentID: "agent-1",
274 })
275
276 state := sess.State()
277
278 // Test Set and Get
279 t.Run("SetGet", func(t *testing.T) {
280 err := state.Set("key1", "value1")
281 if err != nil {
282 t.Fatalf("Set failed: %v", err)
283 }
284
285 val, err := state.Get("key1")
286 if err != nil {
287 t.Fatalf("Get failed: %v", err)
288 }
289
290 if val != "value1" {
291 t.Errorf("Expected 'value1', got %v", val)
292 }
293 })
294
295 // Test Get not found
296 t.Run("GetNotFound", func(t *testing.T) {
297 _, err := state.Get("non-existent")
298 if !errors.Is(err, session.ErrStateKeyNotExist) {
299 t.Errorf("Expected ErrStateKeyNotExist, got %v", err)
300 }
301 })
302
303 // Test Has
304 t.Run("Has", func(t *testing.T) {
305 _ = state.Set("exists", true)
306
307 if !state.Has("exists") {
308 t.Error("Has should return true for existing key")
309 }
310 if state.Has("not-exists") {
311 t.Error("Has should return false for non-existing key")
312 }
313 })
314

Callers

nothing calls this directly

Calls 14

NewFunction · 0.70
CloseMethod · 0.65
CreateMethod · 0.65
StateMethod · 0.65
SetMethod · 0.65
GetMethod · 0.65
HasMethod · 0.65
ErrorMethod · 0.65
DeleteMethod · 0.65
AllMethod · 0.65
UpdateStateMethod · 0.65
IDMethod · 0.65

Tested by

no test coverage detected