♻️ Replace HashType with Hasher

Compatible with crypto.Hash
This commit is contained in:
Dan Jones 2025-03-15 20:09:38 -05:00
commit 2440f55563
5 changed files with 47 additions and 95 deletions

View file

@ -1,6 +1,7 @@
package nomino
import (
"crypto"
"testing"
"github.com/stretchr/testify/assert"
@ -22,21 +23,15 @@ func TestSlugRemovesOriginal(t *testing.T) {
}
func TestHashBadHash(t *testing.T) {
conf := NewConfig(WithOriginal("foobar"), WithGenerator(Hash(0)))
conf := NewConfig(WithOriginal("foobar"), WithGenerator(Hash(crypto.MD5SHA1)))
st, err := conf.generator(&conf)
assert.Equal(t, "", st)
assert.ErrorIs(t, err, ErrInvalidHashType)
assert.ErrorContains(t, err, "invalid hash type: HashType(0)")
assert.ErrorIs(t, err, ErrInvalidHash)
}
func TestHashMissingOriginal(t *testing.T) {
conf := NewConfig(WithGenerator(Hash(HashMD5)))
conf := NewConfig(WithGenerator(Hash(nil)))
st, err := conf.generator(&conf)
assert.Equal(t, "", st)
assert.ErrorIs(t, err, ErrMissingOriginal)
}
func TestHashTypeStringer(t *testing.T) {
s := HashMD5.String()
assert.Equal(t, "MD5", s)
}