// Test the creation of identifiers based on types. func TestTypeAsIdentifierPart(t *testing.T) { assert := asserts.NewTestingAssertion(t, true) // Type as identifier. var tai TypeToSplitForIdentifier id := identifier.TypeAsIdentifierPart(tai) assert.Equal(id, "type-to-split-for-identifier", "wrong TypeAsIdentifierPart() result") id = identifier.TypeAsIdentifierPart(identifier.NewUUID()) assert.Equal(id, "u-u-i-d", "wrong TypeAsIdentifierPart() result") }
// StartLimited creates and runs a new scene with an inactivity // and an absolute timeout. They may be zero. func StartLimited(inactivity, absolute time.Duration) Scene { s := &scene{ id: identifier.NewUUID(), props: make(map[string]*box), flags: make(map[string]bool), signalings: make(map[string][]chan struct{}), inactivity: inactivity, absolute: absolute, commandChan: make(chan *envelope, 1), } s.backend = loop.Go(s.backendLoop) return s }
// Test the standard UUID. func TestStandardUUID(t *testing.T) { assert := asserts.NewTestingAssertion(t, true) // Asserts. uuid := identifier.NewUUID() assert.Equal(uuid.Version(), identifier.UUIDv4) uuidStr := uuid.String() assert.Equal(len(uuid), 16, "UUID length has to be 16") assert.Match(uuidStr, "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", "UUID has to match") // Check for unique creation, but only weak test. uuids := make(map[string]bool) for i := 0; i < 1000000; i++ { uuid = identifier.NewUUID() uuidStr = uuid.String() assert.False(uuids[uuidStr], "UUID collision must not happen") uuids[uuidStr] = true } // Check for copy. uuidA := identifier.NewUUID() uuidB := uuidA.Copy() for i := 0; i < len(uuidA); i++ { uuidA[i] = 0 } assert.Different(uuidA, uuidB) }