db_mtimes_test.go 1023 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright (C) 2025 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. package sqlite
  7. import (
  8. "testing"
  9. "time"
  10. )
  11. func TestMtimePairs(t *testing.T) {
  12. t.Parallel()
  13. db, err := Open(t.TempDir())
  14. if err != nil {
  15. t.Fatal()
  16. }
  17. t.Cleanup(func() {
  18. if err := db.Close(); err != nil {
  19. t.Fatal(err)
  20. }
  21. })
  22. t0 := time.Now().Truncate(time.Second)
  23. t1 := t0.Add(1234567890)
  24. // Set a pair
  25. if err := db.PutMtime("foo", "bar", t0, t1); err != nil {
  26. t.Fatal(err)
  27. }
  28. // Check it
  29. gt0, gt1 := db.GetMtime("foo", "bar")
  30. if !gt0.Equal(t0) || !gt1.Equal(t1) {
  31. t.Log(t0, gt0)
  32. t.Log(t1, gt1)
  33. t.Log("bad times")
  34. }
  35. // Delete it
  36. if err := db.DeleteMtime("foo", "bar"); err != nil {
  37. t.Fatal(err)
  38. }
  39. // Check it
  40. gt0, gt1 = db.GetMtime("foo", "bar")
  41. if !gt0.IsZero() || !gt1.IsZero() {
  42. t.Log(gt0, gt1)
  43. t.Log("bad times")
  44. }
  45. }