mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
chore: add tests for heartbeat hashing
This commit is contained in:
parent
3922c3767d
commit
97a10cc08a
@ -64,3 +64,42 @@ func TestHeartbeat_GetKey(t *testing.T) {
|
|||||||
assert.Equal(t, UnknownSummaryKey, sut.GetKey(SummaryEditor))
|
assert.Equal(t, UnknownSummaryKey, sut.GetKey(SummaryEditor))
|
||||||
assert.Equal(t, UnknownSummaryKey, sut.GetKey(255))
|
assert.Equal(t, UnknownSummaryKey, sut.GetKey(255))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestHeartbeat_Hashed(t *testing.T) {
|
||||||
|
var sut1, sut2 *Heartbeat
|
||||||
|
|
||||||
|
// same hash if only non-hashed fields are different
|
||||||
|
sut1 = &Heartbeat{Entity: "file1", Editor: "vscode", Time: CustomTime(time.Unix(1673810732, 0))}
|
||||||
|
sut2 = &Heartbeat{Entity: "file1", Editor: "goland", Time: CustomTime(time.Unix(1673810732, 0))}
|
||||||
|
assert.Equal(t, sut1.Hashed().Hash, sut2.Hashed().Hash)
|
||||||
|
|
||||||
|
// different hash if time is different
|
||||||
|
sut1 = &Heartbeat{Entity: "file1", Editor: "vscode", Time: CustomTime(time.Unix(1673810732, 0))}
|
||||||
|
sut2 = &Heartbeat{Entity: "file1", Editor: "goland", Time: CustomTime(time.Unix(1673810733, 0))}
|
||||||
|
assert.NotEqual(t, sut1.Hashed().Hash, sut2.Hashed().Hash)
|
||||||
|
|
||||||
|
// different hash if any other hashed field is different
|
||||||
|
sut1 = &Heartbeat{Entity: "file1", Editor: "vscode", Time: CustomTime(time.Unix(1673810732, 0))}
|
||||||
|
sut2 = &Heartbeat{Entity: "file2", Editor: "goland", Time: CustomTime(time.Unix(1673810732, 0))}
|
||||||
|
assert.NotEqual(t, sut1.Hashed().Hash, sut2.Hashed().Hash)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestHeartbeat_Hashed_NoCollision(t *testing.T) {
|
||||||
|
hashes := map[string]bool{}
|
||||||
|
|
||||||
|
for i := 0; i < 2500; i++ {
|
||||||
|
sut := &Heartbeat{
|
||||||
|
UserID: "gopher",
|
||||||
|
Entity: "~/dev/wakapi",
|
||||||
|
Type: "file",
|
||||||
|
Category: "coding",
|
||||||
|
Project: "wakapi",
|
||||||
|
Branch: "master",
|
||||||
|
Language: "go",
|
||||||
|
IsWrite: false,
|
||||||
|
Time: CustomTime(time.Unix(1673810732+int64(i), 0)),
|
||||||
|
}
|
||||||
|
assert.NotContains(t, hashes, sut.Hashed().Hash)
|
||||||
|
hashes[sut.Hash] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user