TestErrorHandling verifies proper error responses for invalid operations.
(t *testing.T)
| 332 | |
| 333 | // TestErrorHandling verifies proper error responses for invalid operations. |
| 334 | func TestErrorHandling(t *testing.T) { |
| 335 | t.Run("FileStoreWriteError", func(t *testing.T) { |
| 336 | // Test file write to invalid path |
| 337 | kb := knowledgeBase{ |
| 338 | s: &fileStore{path: filepath.Join("nonexistent", "directory", "file.json")}, |
| 339 | } |
| 340 | |
| 341 | testEntities := []Entity{ |
| 342 | {Name: "TestEntity"}, |
| 343 | } |
| 344 | |
| 345 | _, err := kb.createEntities(testEntities) |
| 346 | if err == nil { |
| 347 | t.Errorf("expected error when writing to non-existent directory, got nil") |
| 348 | } |
| 349 | }) |
| 350 | |
| 351 | for name, newStore := range stores() { |
| 352 | t.Run(fmt.Sprintf("AddObservationToNonExistentEntity_%s", name), func(t *testing.T) { |
| 353 | s := newStore(t) |
| 354 | kb := knowledgeBase{s: s} |
| 355 | |
| 356 | // Setup valid entity for comparison |
| 357 | _, err := kb.createEntities([]Entity{{Name: "RealEntity"}}) |
| 358 | if err != nil { |
| 359 | t.Fatalf("failed to create test entity: %v", err) |
| 360 | } |
| 361 | |
| 362 | // Test invalid entity reference |
| 363 | nonExistentObs := []Observation{ |
| 364 | { |
| 365 | EntityName: "NonExistentEntity", |
| 366 | Contents: []string{"This shouldn't work"}, |
| 367 | }, |
| 368 | } |
| 369 | |
| 370 | _, err = kb.addObservations(nonExistentObs) |
| 371 | if err == nil { |
| 372 | t.Errorf("expected error when adding observations to non-existent entity, got nil") |
| 373 | } |
| 374 | }) |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | // TestFileFormatting verifies the JSON storage format structure. |
| 379 | func TestFileFormatting(t *testing.T) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…