github.com/eden-framework/sqlx@v0.0.2/builder/def_column_test.go (about)

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