mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
Summary: Go plugin is not a good solution for both internal and external usage. It's hard to manage and maintain matching versions (both Go and external libraries), and it does not support Windows. Reviewed By: alexsn Differential Revision: D16582217 fbshipit-source-id: 81876d2c6f30bbfc16ecf9e5000f0670f2e62484
58 lines
1.7 KiB
Go
58 lines
1.7 KiB
Go
package edge_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"fbc/ent"
|
|
"fbc/ent/edge"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestEdge(t *testing.T) {
|
|
assert := assert.New(t)
|
|
type User struct{ ent.Schema }
|
|
e := edge.To("friends", User.Type).Required()
|
|
assert.False(e.IsInverse())
|
|
assert.Equal("User", e.Type())
|
|
assert.Equal("friends", e.Name())
|
|
assert.True(e.IsRequired())
|
|
|
|
type Node struct{ ent.Schema }
|
|
e = edge.To("parent", Node.Type).Unique()
|
|
assert.False(e.IsInverse())
|
|
assert.True(e.IsUnique())
|
|
assert.Equal("Node", e.Type())
|
|
assert.Equal("parent", e.Name())
|
|
assert.False(e.IsRequired())
|
|
|
|
t.Log("m2m relation of the same type")
|
|
from := edge.To("following", User.Type).From("followers")
|
|
|
|
assert.True(from.IsInverse())
|
|
assert.False(from.IsUnique())
|
|
assert.Equal("followers", from.Name())
|
|
assert.NotNil(from.Assoc())
|
|
assert.Equal("following", from.Assoc().Name())
|
|
assert.False(from.Assoc().IsUnique())
|
|
|
|
t.Log("o2m relation of the same type")
|
|
from = edge.To("following", User.Type).Unique().From("followers")
|
|
assert.False(from.IsUnique())
|
|
assert.True(from.Assoc().IsUnique())
|
|
from = edge.To("following", User.Type).From("followers").Unique()
|
|
assert.True(from.IsUnique())
|
|
assert.False(from.Assoc().IsUnique())
|
|
|
|
t.Log("o2o relation of the same type")
|
|
from = edge.To("following", User.Type).Unique().From("followers").Unique()
|
|
assert.True(from.IsUnique())
|
|
assert.True(from.Assoc().IsUnique())
|
|
|
|
e = edge.To("user", User.Type).StructTag(`json:"user_name,omitempty"`)
|
|
assert.Equal(`json:"user_name,omitempty"`, e.Tag())
|
|
from = edge.To("following", User.Type).StructTag("following").From("followers").StructTag("followers")
|
|
assert.Equal("followers", from.Tag())
|
|
assert.Equal("following", from.Assoc().Tag())
|
|
}
|