nomino/gen_file_test.go
Dan Jones 2440f55563 ♻️ Replace HashType with Hasher
Compatible with crypto.Hash
2025-03-15 20:09:38 -05:00

37 lines
935 B
Go

package nomino
import (
"crypto"
"testing"
"github.com/stretchr/testify/assert"
)
func TestSlugMissingFilename(t *testing.T) {
conf := NewConfig(WithGenerator(Slug()))
st, err := conf.generator(&conf)
assert.Zero(t, st)
assert.ErrorIs(t, err, ErrMissingOriginal)
}
func TestSlugRemovesOriginal(t *testing.T) {
conf := NewConfig(WithGenerator(Slug()), WithOriginal("Hello, World"))
st, err := conf.generator(&conf)
assert.Zero(t, conf.original)
assert.Equal(t, "hello-world", st)
assert.NoError(t, err)
}
func TestHashBadHash(t *testing.T) {
conf := NewConfig(WithOriginal("foobar"), WithGenerator(Hash(crypto.MD5SHA1)))
st, err := conf.generator(&conf)
assert.Equal(t, "", st)
assert.ErrorIs(t, err, ErrInvalidHash)
}
func TestHashMissingOriginal(t *testing.T) {
conf := NewConfig(WithGenerator(Hash(nil)))
st, err := conf.generator(&conf)
assert.Equal(t, "", st)
assert.ErrorIs(t, err, ErrMissingOriginal)
}