🚚 Move Slug/Hash Generators to own file

This commit is contained in:
Dan Jones 2025-03-14 19:50:24 -05:00
commit 1d0f2238b3
7 changed files with 193 additions and 162 deletions

View file

@ -82,38 +82,3 @@ func TestUUIDFail(t *testing.T) {
_, err := UUID()(nil)
assert.Equal(t, errors.New("sorry"), err)
}
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(0)))
st, err := conf.generator(&conf)
assert.Equal(t, "", st)
assert.ErrorIs(t, err, ErrInvalidHashType)
assert.ErrorContains(t, err, "invalid hash type: HashType(0)")
}
func TestHashMissingOriginal(t *testing.T) {
conf := NewConfig(WithGenerator(Hash(MD5)))
st, err := conf.generator(&conf)
assert.Equal(t, "", st)
assert.ErrorIs(t, err, ErrMissingOriginal)
}
func TestHashTypeStringer(t *testing.T) {
s := MD5.String()
assert.Equal(t, "MD5", s)
}