github.com/kunlun-qilian/sqlx/v3@v3.0.0/builder/column_type_test.go (about)

     1  package builder_test
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  
     7  	"github.com/go-courier/x/ptr"
     8  	"github.com/go-courier/x/types"
     9  	. "github.com/kunlun-qilian/sqlx/v3/builder"
    10  	"github.com/onsi/gomega"
    11  )
    12  
    13  func TestColumnTypeFromTypeAndTag(t *testing.T) {
    14  	cases := map[string]*ColumnType{
    15  		`,deprecated=f_target_env_id`: &ColumnType{
    16  			Type:              types.FromRType(reflect.TypeOf(1)),
    17  			DeprecatedActions: &DeprecatedActions{RenameTo: "f_target_env_id"},
    18  		},
    19  		`,autoincrement`: &ColumnType{
    20  			Type:          types.FromRType(reflect.TypeOf(1)),
    21  			AutoIncrement: true,
    22  		},
    23  		`,null`: &ColumnType{
    24  			Type: types.FromRType(reflect.TypeOf(float64(1.1))),
    25  			Null: true,
    26  		},
    27  		`,size=2`: &ColumnType{
    28  			Type:   types.FromRType(reflect.TypeOf("")),
    29  			Length: 2,
    30  		},
    31  		`,decimal=1`: &ColumnType{
    32  			Type:    types.FromRType(reflect.TypeOf(float64(1.1))),
    33  			Decimal: 1,
    34  		},
    35  		`,default='1'`: &ColumnType{
    36  			Type:    types.FromRType(reflect.TypeOf("")),
    37  			Default: ptr.String(`'1'`),
    38  		},
    39  	}
    40  
    41  	for tagValue, ct := range cases {
    42  		t.Run(tagValue, func(t *testing.T) {
    43  			gomega.NewWithT(t).Expect(ColumnTypeFromTypeAndTag(ct.Type, tagValue)).To(gomega.Equal(ct))
    44  		})
    45  	}
    46  }