♻️ Refactor Timestamp Generator to single function with options
This commit is contained in:
parent
72791d4fac
commit
61a5199699
5 changed files with 113 additions and 67 deletions
|
|
@ -2,9 +2,7 @@ package nomino
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
|
@ -85,28 +83,6 @@ func TestUUIDFail(t *testing.T) {
|
|||
assert.Equal(t, errors.New("sorry"), err)
|
||||
}
|
||||
|
||||
func TestTimestamp(t *testing.T) {
|
||||
n := time.Now()
|
||||
st, err := Timestamp()(nil)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, n.Format(FileTimestamp), st)
|
||||
}
|
||||
|
||||
func TestTime(t *testing.T) {
|
||||
d := time.Date(1986, time.March, 28, 12, 0, 0, 0, time.UTC)
|
||||
|
||||
st, err := Time(d)(nil)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, d.Format(FileTimestamp), st)
|
||||
}
|
||||
|
||||
func TestTimestampUTC(t *testing.T) {
|
||||
n := time.Now()
|
||||
st, err := TimestampUTC()(nil)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, n.UTC().Format(FileTimestampNoTZ), st)
|
||||
}
|
||||
|
||||
func TestSlugMissingFilename(t *testing.T) {
|
||||
conf := NewConfig(WithGenerator(Slug()))
|
||||
st, err := conf.generator(&conf)
|
||||
|
|
@ -138,6 +114,6 @@ func TestHashMissingOriginal(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestHashTypeStringer(t *testing.T) {
|
||||
s := fmt.Sprintf("%s", MD5)
|
||||
s := MD5.String()
|
||||
assert.Equal(t, "MD5", s)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue