mirror of
https://github.com/ent/ent.git
synced 2026-05-22 09:31:45 +03:00
Summary: Used addlicense to generate this: addlicense -c "Facebook Inc" -f license_header . example was taken from: https://github.com/facebook/litho/blob/master/lib/soloader/BUCK Reviewed By: alexsn Differential Revision: D17070152 fbshipit-source-id: e7b91398d7f6181727be3400c1872ad5f28e38ed
66 lines
1.8 KiB
Go
66 lines
1.8 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 load
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/facebookincubator/ent/schema/field"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestLoad(t *testing.T) {
|
|
cfg := &Config{Path: "./testdata/valid"}
|
|
spec, err := cfg.Load()
|
|
require.NoError(t, err)
|
|
require.Len(t, spec.Schemas, 3)
|
|
require.Equal(t, "github.com/facebookincubator/ent/entc/load/testdata/valid", spec.PkgPath)
|
|
}
|
|
|
|
func TestLoadWrongPath(t *testing.T) {
|
|
cfg := &Config{Path: "./boring"}
|
|
plg, err := cfg.Load()
|
|
require.Error(t, err)
|
|
require.Nil(t, plg)
|
|
}
|
|
|
|
func TestLoadSpecific(t *testing.T) {
|
|
cfg := &Config{Path: "./testdata/valid", Names: []string{"User"}}
|
|
spec, err := cfg.Load()
|
|
require.NoError(t, err)
|
|
require.Len(t, spec.Schemas, 1)
|
|
require.Equal(t, "User", spec.Schemas[0].Name)
|
|
require.Equal(t, "github.com/facebookincubator/ent/entc/load/testdata/valid", spec.PkgPath)
|
|
}
|
|
|
|
func TestLoadNoSchema(t *testing.T) {
|
|
cfg := &Config{Path: "./testdata/invalid"}
|
|
schemas, err := cfg.Load()
|
|
require.Error(t, err)
|
|
require.Empty(t, schemas)
|
|
}
|
|
|
|
func TestLoadSchemaFailure(t *testing.T) {
|
|
cfg := &Config{Path: "./testdata/failure"}
|
|
spec, err := cfg.Load()
|
|
require.Error(t, err)
|
|
require.Nil(t, spec)
|
|
}
|
|
|
|
func TestLoadBaseSchema(t *testing.T) {
|
|
cfg := &Config{Path: "./testdata/base"}
|
|
spec, err := cfg.Load()
|
|
require.NoError(t, err)
|
|
require.Len(t, spec.Schemas, 1)
|
|
require.Len(t, spec.Schemas[0].Fields, 2, "embedded base schema")
|
|
f1 := spec.Schemas[0].Fields[0]
|
|
require.Equal(t, "base_field", f1.Name)
|
|
require.Equal(t, field.TypeInt, f1.Type)
|
|
f2 := spec.Schemas[0].Fields[1]
|
|
require.Equal(t, "user_field", f2.Name)
|
|
require.Equal(t, field.TypeString, f2.Type)
|
|
}
|