mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
Reviewed By: alexsn Differential Revision: D17953335 fbshipit-source-id: 6178e4121a4bbd241374f1d6ad5a447188d48fb1
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
// Copyright 2019-present Facebook Inc. All rights reserved.
|
|
// This source code is licensed under the Apache 2.0 license found
|
|
// in the LICENSE file in the root directory of this source tree.
|
|
|
|
package schemautil
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestTimeMixin(t *testing.T) {
|
|
t.Run("Create", func(t *testing.T) {
|
|
t.Parallel()
|
|
fields := CreateTimeMixin{}.Fields()
|
|
require.Len(t, fields, 1)
|
|
desc := fields[0].Descriptor()
|
|
assert.Equal(t, "created_at", desc.Name)
|
|
assert.True(t, desc.Immutable)
|
|
assert.NotNil(t, desc.Default)
|
|
assert.Nil(t, desc.UpdateDefault)
|
|
})
|
|
t.Run("Update", func(t *testing.T) {
|
|
t.Parallel()
|
|
fields := UpdateTimeMixin{}.Fields()
|
|
require.Len(t, fields, 1)
|
|
desc := fields[0].Descriptor()
|
|
assert.Equal(t, "updated_at", desc.Name)
|
|
assert.True(t, desc.Immutable)
|
|
assert.NotNil(t, desc.Default)
|
|
assert.NotNil(t, desc.UpdateDefault)
|
|
})
|
|
t.Run("Compose", func(t *testing.T) {
|
|
t.Parallel()
|
|
fields := TimeMixin{}.Fields()
|
|
require.Len(t, fields, 2)
|
|
assert.Equal(t, "created_at", fields[0].Descriptor().Name)
|
|
assert.Equal(t, "updated_at", fields[1].Descriptor().Name)
|
|
})
|
|
}
|