syncdb_test.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package syncdb
  2. import (
  3. "testing"
  4. )
  5. func TestSyncDB_Store(t *testing.T) {
  6. syncDB := NewSyncDB()
  7. // Store a value in the SyncDB
  8. uuid := syncDB.Store("TestValue")
  9. // Read the value from the SyncDB
  10. result := syncDB.Read(uuid)
  11. // Verify that the value is stored and retrieved correctly
  12. if result != "TestValue" {
  13. t.Errorf("Expected 'TestValue', got %s", result)
  14. }
  15. }
  16. func TestSyncDB_Read(t *testing.T) {
  17. syncDB := NewSyncDB()
  18. // Store a value in the SyncDB
  19. uuid := syncDB.Store("TestValue")
  20. // Read the value from the SyncDB
  21. result := syncDB.Read(uuid)
  22. // Verify that the value is stored and retrieved correctly
  23. if result != "TestValue" {
  24. t.Errorf("Expected 'TestValue', got %s", result)
  25. }
  26. // Try to read a non-existent UUID
  27. nonExistentResult := syncDB.Read("NonExistentUUID")
  28. // Verify that the result is empty for non-existent UUID
  29. if nonExistentResult != "" {
  30. t.Errorf("Expected empty result for non-existent UUID, got %s", nonExistentResult)
  31. }
  32. }
  33. func TestSyncDB_Delete(t *testing.T) {
  34. syncDB := NewSyncDB()
  35. // Store a value in the SyncDB
  36. uuid := syncDB.Store("TestValue")
  37. // Delete the stored value
  38. syncDB.Delete(uuid)
  39. // Try to read the deleted value
  40. deletedResult := syncDB.Read(uuid)
  41. // Verify that the result is empty for the deleted UUID
  42. if deletedResult != "" {
  43. t.Errorf("Expected empty result for deleted UUID, got %s", deletedResult)
  44. }
  45. }
  46. /*
  47. func TestSyncDB_AutoCleaning(t *testing.T) {
  48. syncDB := NewSyncDB()
  49. // Store a value in the SyncDB
  50. uuid := syncDB.Store("TestValue")
  51. // Wait for auto-cleaning routine to run
  52. time.Sleep(6 * time.Minute)
  53. // Try to read the cleaned value
  54. cleanedResult := syncDB.Read(uuid)
  55. // Verify that the result is empty for the cleaned UUID
  56. if cleanedResult != "" {
  57. t.Errorf("Expected empty result for cleaned UUID, got %s", cleanedResult)
  58. }
  59. }
  60. */
  61. func TestSyncDB_ToString(t *testing.T) {
  62. syncDB := NewSyncDB()
  63. // Store some values in the SyncDB
  64. syncDB.Store("Value1")
  65. syncDB.Store("Value2")
  66. // Display the contents of the SyncDB
  67. syncDB.ToString()
  68. // Verify that the values are displayed correctly
  69. // This should be manually inspected as it prints to stdout
  70. }