♻️ Replace HashType with Hasher
Compatible with crypto.Hash
This commit is contained in:
parent
1008a064d0
commit
2440f55563
5 changed files with 47 additions and 95 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue