Files
navidrome/utils/hasher/hasher_test.go
Guilherme Souza 98218d045e Deterministic pagination in random albums sort (#1841)
* Deterministic pagination in random albums sort

* Reseed on first random page

* Add unit tests

* Use rand in Subsonic API

* Use different seeds per user on SEEDEDRAND() SQLite3 function

* Small refactor

* Fix id mismatch

* Add seeded random to media_file (subsonic endpoint `getRandomSongs`)

* Refactor

* Remove unneeded import

---------

Co-authored-by: Deluan <deluan@navidrome.org>
2024-05-18 14:10:53 -04:00

37 lines
886 B
Go

package hasher_test
import (
"github.com/navidrome/navidrome/utils/hasher"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("HashFunc", func() {
const input = "123e4567e89b12d3a456426614174000"
It("hashes the input and returns the sum", func() {
hashFunc := hasher.HashFunc()
sum := hashFunc("1", input)
Expect(sum > 0).To(BeTrue())
})
It("hashes the input, reseeds and returns a different sum", func() {
hashFunc := hasher.HashFunc()
sum := hashFunc("1", input)
hasher.Reseed("1")
sum2 := hashFunc("1", input)
Expect(sum).NotTo(Equal(sum2))
})
It("keeps different hashes for different ids", func() {
hashFunc := hasher.HashFunc()
sum := hashFunc("1", input)
sum2 := hashFunc("2", input)
Expect(sum).NotTo(Equal(sum2))
Expect(sum).To(Equal(hashFunc("1", input)))
Expect(sum2).To(Equal(hashFunc("2", input)))
})
})