resolve dangliing hashes

This commit is contained in:
2026-04-21 11:47:56 +02:00
parent 682b7a0228
commit 0a25bd559c
14 changed files with 390 additions and 59 deletions
+18
View File
@@ -1,18 +1,36 @@
package handler
import (
"crypto/rand"
"errors"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
type errorReader struct{}
func (e errorReader) Read(p []byte) (n int, err error) {
return 0, errors.New("read error")
}
func TestGenerateId(t *testing.T) {
id, err := generateId()
assert.NoError(t, err)
assert.Equal(t, 10, len(id))
}
func TestGenerateIdError(t *testing.T) {
originalReader := rand.Reader
defer func() { rand.Reader = originalReader }()
rand.Reader = errorReader{}
id, err := generateId()
assert.Error(t, err)
assert.Empty(t, id)
}
func TestHash(t *testing.T) {
c := "test content"
h1 := hash(c)