MCPcopy
hub / github.com/google/uuid / TestVersion6

Function TestVersion6

uuid_test.go:784–821  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

782}
783
784func TestVersion6(t *testing.T) {
785 uuid1, err := NewV6()
786 if err != nil {
787 t.Fatalf("could not create UUID: %v", err)
788 }
789 uuid2, err := NewV6()
790 if err != nil {
791 t.Fatalf("could not create UUID: %v", err)
792 }
793
794 if uuid1 == uuid2 {
795 t.Errorf("%s:duplicate uuid", uuid1)
796 }
797 if v := uuid1.Version(); v != 6 {
798 t.Errorf("%s: version %s expected 6", uuid1, v)
799 }
800 if v := uuid2.Version(); v != 6 {
801 t.Errorf("%s: version %s expected 6", uuid2, v)
802 }
803 n1 := uuid1.NodeID()
804 n2 := uuid2.NodeID()
805 if !bytes.Equal(n1, n2) {
806 t.Errorf("Different nodes %x != %x", n1, n2)
807 }
808 t1 := uuid1.Time()
809 t2 := uuid2.Time()
810 q1 := uuid1.ClockSequence()
811 q2 := uuid2.ClockSequence()
812
813 switch {
814 case t1 == t2 && q1 == q2:
815 t.Error("time stopped")
816 case t1 > t2 && q1 == q2:
817 t.Error("time reversed")
818 case t1 < t2 && q1 != q2:
819 t.Error("clock sequence changed unexpectedly")
820 }
821}
822
823// uuid v7 time is only unix milliseconds, so
824// uuid1.Time() == uuid2.Time() is right, but uuid1 must != uuid2

Callers

nothing calls this directly

Calls 6

NewV6Function · 0.85
VersionMethod · 0.80
NodeIDMethod · 0.80
TimeMethod · 0.80
ClockSequenceMethod · 0.80
ErrorMethod · 0.80

Tested by

no test coverage detected