Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vmercierfr committed Apr 16, 2024
1 parent 63ee95e commit 7005c97
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions internal/infra/uuid7/uuid7_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package uuid7_test

import (
"testing"
"time"

"github.com/google/uuid"
"github.com/qonto/postgresql-partition-manager/internal/infra/uuid7"
"github.com/stretchr/testify/assert"
)

const UUIDv7Version uuid.Version = 7

func TestFromTime(t *testing.T) {
testCases := []struct {
timestamp time.Time
}{
{
time.Date(2024, 1, 20, 0, 0, 0, 0, time.UTC),
},
}

for _, tc := range testCases {
t.Run(tc.timestamp.String(), func(t *testing.T) {
generated := uuid7.FromTime(tc.timestamp)

decoded, err := uuid.Parse(generated)
timestamp, _ := decoded.Time().UnixTime()

assert.Nil(t, err, "UUID should be parsable")
assert.Equal(t, decoded.Version(), UUIDv7Version, "Should be an UUIDv7")
assert.Equal(t, timestamp, tc.timestamp.Unix(), "Timestamp from generated UUID should match")
})
}
}

0 comments on commit 7005c97

Please sign in to comment.