init monlet repo with stage 0-2 (docs, contract, agent MVP)
This commit is contained in:
12
agent/internal/eventid/eventid.go
Normal file
12
agent/internal/eventid/eventid.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package eventid
|
||||
|
||||
import "github.com/google/uuid"
|
||||
|
||||
// New returns a UUIDv7 in canonical lower-case form.
|
||||
func New() (string, error) {
|
||||
id, err := uuid.NewV7()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return id.String(), nil
|
||||
}
|
||||
20
agent/internal/eventid/eventid_test.go
Normal file
20
agent/internal/eventid/eventid_test.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package eventid
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var pattern = regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$`)
|
||||
|
||||
func TestNewMatchesContract(t *testing.T) {
|
||||
for i := 0; i < 100; i++ {
|
||||
id, err := New()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !pattern.MatchString(id) {
|
||||
t.Fatalf("invalid UUIDv7: %q", id)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user