From 7005c97451ba7ffdad4c3a9dc3c295d091b4d139 Mon Sep 17 00:00:00 2001 From: Vincent Mercier Date: Tue, 16 Apr 2024 15:46:06 +0200 Subject: [PATCH] fix --- internal/infra/uuid7/uuid7_test.go | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 internal/infra/uuid7/uuid7_test.go diff --git a/internal/infra/uuid7/uuid7_test.go b/internal/infra/uuid7/uuid7_test.go new file mode 100644 index 0000000..5c56f67 --- /dev/null +++ b/internal/infra/uuid7/uuid7_test.go @@ -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") + }) + } +}