37 lines
935 B
Go
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)
|
|
}
|