Files
syncthing/lib/stats/stats_test.go
Jakob Borg 025905fcdf chore: switch database engine to sqlite (fixes #9954) (#9965)
Switch the database from LevelDB to SQLite, for greater stability and
simpler code.

Co-authored-by: Tommy van der Vorst <tommy@pixelspark.nl>
Co-authored-by: bt90 <btom1990@googlemail.com>
2025-03-29 13:50:08 +01:00

49 lines
1.1 KiB
Go

// Copyright (C) 2020 The Syncthing Authors.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.
// The existence of this file means we get 0% test coverage rather than no
// test coverage at all. Remove when implementing an actual test.
package stats
import (
"testing"
"time"
"github.com/syncthing/syncthing/internal/db"
"github.com/syncthing/syncthing/internal/db/sqlite"
)
func TestDeviceStat(t *testing.T) {
sdb, err := sqlite.OpenTemp()
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
sdb.Close()
})
sr := NewDeviceStatisticsReference(db.NewTyped(sdb, "devstatref"))
if err := sr.WasSeen(); err != nil {
t.Fatal(err)
}
if err := sr.LastConnectionDuration(42 * time.Second); err != nil {
t.Fatal(err)
}
stat, err := sr.GetStatistics()
if err != nil {
t.Fatal(err)
}
if d := time.Since(stat.LastSeen); d > 5*time.Second {
t.Error("Last seen far in the past:", d)
}
if d := stat.LastConnectionDurationS; d != 42 {
t.Error("Bad last duration:", d)
}
}